<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Akhil Gautam on Medium]]></title>
        <description><![CDATA[Stories by Akhil Gautam on Medium]]></description>
        <link>https://medium.com/@akhilgautam?source=rss-5bc3502a936a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TN9Yi7ox4Fnbn8xG.</url>
            <title>Stories by Akhil Gautam on Medium</title>
            <link>https://medium.com/@akhilgautam?source=rss-5bc3502a936a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:09:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akhilgautam/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Loaders are quite common web components that we see on the web.]]></title>
            <link>https://akhilgautam.medium.com/loaders-are-quite-common-web-components-that-we-see-on-the-web-7cbcd56cfefc?source=rss-5bc3502a936a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cbcd56cfefc</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css-animation]]></category>
            <dc:creator><![CDATA[Akhil Gautam]]></dc:creator>
            <pubDate>Sat, 05 Dec 2020 19:11:03 GMT</pubDate>
            <atom:updated>2020-12-05T19:18:42.433Z</atom:updated>
            <content:encoded><![CDATA[<h3>Loading animations in vanilla CSS</h3><p>Loaders are quite common web components that we see on the web. It presents a really decent UX and make the client aware of something being loaded. In this blog we will see how to create some of the very basic loading animations in pure CSS.</p><h3>- Ring Loader</h3><p>Most of the animations are based on two properties: borders and keyframes.</p><p><strong>STEP-1:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/0*i-HP5zQk7rRYUlHb" /></figure><p>Create a square box, with a different border-color on any one of the sides.</p><pre>.loader-1 {<br>  height: 100px;<br>  width: 100px;<br>  border: 10px solid #ccc;<br>  border-right-color: #673AB7;<br>}</pre><p><strong>STEP-2:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/0*yecQsKPZvx3t5q8v" /></figure><p>Add border-radius to make it circular.</p><pre>.loader-1 {<br>  height: 100px;<br>  width: 100px;<br>  border: 10px solid #ccc;<br>  border-right-color: #673AB7;<br> /* adding border-radius */<br>  border-radius: 50%;<br>}</pre><p><strong>STEP-3: </strong>Now we just need to add animation with a keyframe containing rotate.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fanonymousgautam%2Fembed%2Fpreview%2FOJRNWVO%3Fheight%3D600%26slug-hash%3DOJRNWVO%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fanonymousgautam%2Fpen%2FOJRNWVO&amp;image=https%3A%2F%2Fassets.codepen.io%2F5421481%2Finternal%2Fscreenshots%2Fpens%2FOJRNWVO.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1607186814%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/d20047ba9d3a7328c16d70a10447bc24/href">https://medium.com/media/d20047ba9d3a7328c16d70a10447bc24/href</a></iframe><h3>- Dual Ring Loader</h3><p>All we need to do to create a dual-ring loader is to alternate the border-color with transparent in between. border-color can take upto four different colors as value which are then set as an element&#39;s four sides.</p><pre>.loader-2 {<br>  width: 100px;<br>  height: 100px;<br>  border-radius: 50%;<br>  border: 6px solid #673AB7;<br>  /* alternate border-color for four different sides */<br>  border-color: #673AB7 transparent #673AB7 transparent;<br>  animation: rotate 1.5s linear infinite;<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fanonymousgautam%2Fembed%2Fpreview%2FmdrPRQL%3Fheight%3D600%26slug-hash%3DmdrPRQL%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fanonymousgautam%2Fpen%2FmdrPRQL&amp;image=https%3A%2F%2Fassets.codepen.io%2F5421481%2Finternal%2Fscreenshots%2Fpens%2FmdrPRQL.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1607186913%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/585e95f6ed1bd8aee6af20546430be54/href">https://medium.com/media/585e95f6ed1bd8aee6af20546430be54/href</a></iframe><h3>- Bouncing Bars Loader</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/197/0*nDrjZgjbK6NY0lO7" /></figure><p>This loader primarily involve 3 divs/bars whose height and top is changed in keyframes along with a delay in the animation for each of them.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fanonymousgautam%2Fembed%2Fpreview%2FvYXGxEr%3Fheight%3D600%26slug-hash%3DvYXGxEr%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fanonymousgautam%2Fpen%2FvYXGxEr&amp;image=https%3A%2F%2Fassets.codepen.io%2F5421481%2Finternal%2Fscreenshots%2Fpens%2FvYXGxEr.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1607188837%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/153ad055d20d32da803afb86234c13f5/href">https://medium.com/media/153ad055d20d32da803afb86234c13f5/href</a></iframe><h3>- Conclusion</h3><p>There is no limit to creativity. We can create all different kind of loaders by changing its CSS properties in keyframes.</p><p><em>Originally published at </em><a href="https://blog.akhilgautam.me/loading-animations-in-vanilla-css-ckibz2oxi004pbhs1ao04fwsw"><em>https://blog.akhilgautam.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cbcd56cfefc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best React Component Libraries in 2019]]></title>
            <link>https://akhilgautam.medium.com/best-react-component-libraries-in-2019-3fa1b278fd1?source=rss-5bc3502a936a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fa1b278fd1</guid>
            <category><![CDATA[react-ui-component]]></category>
            <category><![CDATA[best-react-libraries]]></category>
            <category><![CDATA[component-libraries]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Akhil Gautam]]></dc:creator>
            <pubDate>Mon, 10 Jun 2019 05:36:03 GMT</pubDate>
            <atom:updated>2019-06-12T11:00:16.422Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SfKsSG17Swa0PtUrTKAUDg.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@jvdm?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Jean van der Meulen </a>from <a href="https://www.pexels.com/photo/photo-of-living-room-1457842/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><blockquote><strong>People ignore design that ignores people.</strong></blockquote><p>Today we are going to discuss the best React Component Libraries that can be used in 2019. React is no doubt one of the best front-end javascript libraries. The simplicity of its use and component-based architecture adds beauty to it.<br>And because of that, a lot of React components libraries have come into the picture that can provide an ultimate UI/UX with no effort at all. Let’s dive into it.</p><h3>1. MATERIAL-UI</h3><blockquote>React components for faster and easier web development. Build your own design system, or start with Material Design.</blockquote><p>Material-UI is a set rich React Components that implements Google’s Material Design. It contains almost all the components that we will need during the entire development process. Apart from that, if we need some tweaking in the components, it has got built-in <a href="https://material-ui.com/customization/themes/"><em>theming</em></a> support. And the best part is that we don’t need to install the whole package in our codebase, we can install any specific component.</p><p><a href="https://material-ui.com/premium-themes/">React Themes built by or curated by the Material-UI&#39;s creators - Material-UI</a></p><h3>2. ANT DESIGN</h3><blockquote>An enterprise-class UI <strong>design</strong> language and React implementation with a set of high-quality React components, one of the best React UI library for enterprises.</blockquote><p>With more than 40k stars on it’s GitHub repo, it is the second most popular Component Library. It is not only a Component library but a Design Language itself. It is also comprised up of a wide range of ready-to-use component to fulfill and UI requirement. It is written in typescript so it supports typescript out of the box without the need to search its tye definitions here and there. It can be even directly used in the browser from its CDNs but it is often discouraged and suggested to be used with build tools like webpack. You can be a fan of Ant Design just after going to its home page 👌. I have to put it at the number to only because of the lack of Material Design which is a hot cake in the market right now.</p><p><a href="https://ant.design/">Ant Design - The world&#39;s second most popular React UI framework</a></p><h3>3. ATLASKIT</h3><blockquote>Atlassian’s official UI library, built according to the Atlassian Design Guidelines.</blockquote><p>Atlaskit is an open-source library by Atlassian which powers their UI. It has all the components open-sourced that we see while using any Atlassian product. The components are truly amazing and feature rich but still, Atlaskit is not as much famous as the two mentioned above because of two major reasons:<br>1. It is not on GitHub but on Bitbucket <br>2. It is closely coupled with the design language of Atlassian.<br>Though, I would suggest people can go with this and build any UI in no time with this UI kit.</p><p><a href="https://atlaskit.atlassian.com/">Atlaskit by Atlassian</a></p><h3>4. FABRIC</h3><blockquote>Fabric React is a collection of robust React-based components designed to make it simple for you to create consistent web experiences using the Office Design Language.</blockquote><p>Fabric is React component library by Microsoft which is used in almost all the products manufactured under their roof and some of them are Ofice365, Outlook, Onedrive, Sharepoint and many more. Fabric is too good when it comes to creating UI which really pronounces itself. It has got a vast list of components and is well tested to work on all screen sizes without any glitch.<br>The only reason for its less popularity is that people still think Microsoft and Open-Source poles apart. One can build a web app which will appear to be a native Windows application with Fabric. I would suggest every React developer try it at least for once.</p><p><a href="https://developer.microsoft.com/en-us/fabric#/controls/web/">Home - Office UI Fabric</a></p><p><strong>5. Semantic UI React</strong></p><blockquote>Semantic is a development framework that helps create beautiful, responsive layouts using human-friendly HTML.</blockquote><p>Semantic UI React is React implementation of Semantic UI web components. Though Semantic UI depends on jQuery, Semantic UI React is jQuery free and completely re-written to provide the original UI/UX without jQuery. Its UI components are very sleek and intuitive. It may not be at the top in this list but it contains some really beautiful components that are used in day-to-day UI development. Companies like Netflix and Amazon are using Semantic UI in some of their internal applications which speak its fame.</p><p><a href="https://react.semantic-ui.com/">Introduction - Semantic UI React</a></p><p>With that being said, the order that you see here is solely based on my taste and opinion. No of the above better than others, it all depends on use cases. I hope you loved exploring the above libraries and I will be happy if it helped you in your development process.</p><p><a href="/service/mailto: akhilgautam123@gmail.com">Akhil Gautam</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fakhilgautam093944.typeform.com%2Fto%2FwweQE7%3F%26typeform-embed%3Dembedly-full&amp;url=https%3A%2F%2Fakhilgautam093944.typeform.com%2Fto%2FwweQE7&amp;image=https%3A%2F%2Fcdn.glitch.com%2F4416f916-322c-4ea1-b094-9df8005aac4d%252FTypeform%2520-%2520Outside%2520Circle%2520-%2520Black.png%3F1531161183031&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=typeform" width="300" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/16396c704b7cc3709628cf115723d0b1/href">https://medium.com/media/16396c704b7cc3709628cf115723d0b1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fa1b278fd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Splitting in React: Load your bundles blazingly fast]]></title>
            <link>https://akhilgautam.medium.com/code-splitting-in-react-load-your-bundles-blazingly-fast-e45091849dd7?source=rss-5bc3502a936a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e45091849dd7</guid>
            <category><![CDATA[code-splitting]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[react-performance]]></category>
            <dc:creator><![CDATA[Akhil Gautam]]></dc:creator>
            <pubDate>Sun, 12 May 2019 16:19:04 GMT</pubDate>
            <atom:updated>2019-06-10T06:30:11.963Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-38akgbGlp2IA5TUN5G60w.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@goumbik?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Lukas</a> from <a href="https://www.pexels.com/photo/code-coding-computer-data-574073/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p><strong>Prerequisites:<br></strong>1. Basics of React and it’s ecosystem like react-router and webpack.<br>2. ESNext syntax</p><blockquote>What happens when we run <strong><em>npm run build </em></strong><em>in a react app</em>?<br>It initiates a process called <strong><em>bundling</em></strong> which is done by webpack or browserify like tool.<br><strong>Bundling</strong><em> is the process of following imported files and merging them into a single file: a “bundle”. This bundle can then be included on a webpage to load an entire app at once.</em></blockquote><p><strong>Problem 1:</strong> Now when the codebase expands, the bundle size goes on increasing and in some cases it may go beyond 10MBs. The problem with this single bundle file approach is that when a user visits your website for the first time, he/she has to wait until the whole 10MB bundle is downloaded. It has been observed that nearly 90% of users leave a site if it doesn’t load or respond within 10 seconds or less.<br><strong>Problem 2: </strong>Most of the websites will first ask for Log-In and then only a user can browse other pages. Think now, just to open up the Log-In page, the entire bundle has to be loaded first and then only the user can Log-In, though rest of the pages are not required at the time of Log-In.</p><p>To get rid of this huge single bundle file, people came up with the idea of splitting the bundles into multiple tiny chunks which can be loaded only when it is required in the UI. This process of splitting into smaller chunks is what we call code-splitting which is really a buzz word in the world of front-end frameworks.</p><blockquote><a href="https://webpack.js.org/guides/code-splitting/">Code-Splitting</a> is a feature supported by bundlers like Webpack and Browserify (via <a href="https://github.com/browserify/factor-bundle">factor-bundle</a>) which can create multiple bundles that can be dynamically loaded at runtime.</blockquote><p>Let&#39;s address this problem with an easy solution which is built-in inside the webpack. It is going to be less theory more code. We will be creating a simple web-app with 3 pages: Home, About and ContactUs. What we want is to have specific chunks for specific pages so that it downloaded only when the user visits that page.</p><pre>Root path: &#39;<em>/home&#39;<br></em>About section: &#39;/about&#39;<br>ContactUs Section: &#39;/contact&#39;</pre><pre><em>All the above path has to be loaded in different chunks because we will be splitting up the code like that.</em></pre><p><strong>STEP 1: Creating a new app</strong><br>Let&#39;s create a new app using CRA(create-react-app). Please note, I am using Node 10.15.3 and recommend you to use Node 10 or above.</p><pre>// lets create the app my-splitted-app<br>npx create-react-app my-splitted-app</pre><pre>cd my-splitted-app<br>npm install &amp;&amp; npm start</pre><pre>//that&#39;s it your new app is up and running with no charm at all.</pre><p><strong>STEP 2: Adding all 3 pages<br></strong>Now that we have a scaffolded, we will add the 3 pages to our app. Let&#39;s go to <em>src</em> folder and add a new folder name <em>components. </em><strong>We can find the files going into the below sandbox. </strong><br>Please open this sandbox before proceeding with this article. Or you can clone this <a href="https://github.com/akhil-gautam/code-splitting-example-medium">https://github.com/akhil-gautam/code-splitting-example-medium</a> repo if you don’t want to write the entire code and run <strong><em>cd my-app &amp;&amp; npm install &amp;&amp; npm start</em></strong></p><p><a href="https://codesandbox.io/s/github/akhil-gautam/code-splitting-example-medium">my-app - CodeSandbox</a></p><p>Each of the 3 files contains a component with some styling(though poor 😆).<br><strong><em>Home </em></strong>component is the place where we have added Links to the <strong>About</strong> and <strong>ContactUs</strong> pages. <strong>Link </strong>is imported from ‘<em>react-router-dom</em>’ which will create a link to that react page or we can say to that specific chunk. Please note this method of splitting is better known as <em>Route Level Splitting</em> because our bundle will be split based on the route, a chunk for every unique route.</p><p><strong>STEP 3: Import them in App.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc6bb6e4018e5ebba15edee9f0743ab2/href">https://medium.com/media/fc6bb6e4018e5ebba15edee9f0743ab2/href</a></iframe><p>Here a lot of stuff has happened which I will explain in bits. Firstly, Suspense and Lazy are imported from react.<br><strong>React.lazy() </strong>is a HOC which allows react to load components lazily as and when required.<br><strong>Suspense</strong> is used to wrap one or more, lazy components and it has a fallback prop that accepts the react elements you want to render while the lazy component is being loaded.<br>The <strong>Home</strong> component is imported normally as we want it to be the root path of our application and the rest are imported lazily on hitting the routes.</p><pre>Let&#39;s wait for a moment to understand the code below:</pre><pre><strong><em>const About = lazy(() =&gt; <br>    import(/* webpackChunkName: &quot;About&quot; */ &#39;./Components/About&#39;));</em></strong></pre><pre><strong>1.</strong> The import is called as a function to dynamically import a module. When it is used this way, it returns a promise.</pre><pre><strong>2. /* webpackChunkName: &quot;About&quot; */</strong> is used to specify the name of the chunk or else it will be default numbered from 0 to number of lazy loaded components.</pre><p>Now when the user clicks links to different pages, only then it’s corresponding chunk will get loaded.<br>That is it. It is so simple to split our giant single bundle into tiny chunks based on the routes. The user will have to load only those chunks which the current screen requires instead of pushing all at once.</p><p>To verify it, you can open up the developer console and check the network tab. You can watch the video below to see the above code in action.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Ffbef148ef6e5423aba1f3049e6afc891&amp;url=https%3A%2F%2Fwww.loom.com%2Fembed%2Ffbef148ef6e5423aba1f3049e6afc891&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Ffbef148ef6e5423aba1f3049e6afc891-00001.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1152" height="720" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cf0b0435599384f61755a189a9d2a98/href">https://medium.com/media/8cf0b0435599384f61755a189a9d2a98/href</a></iframe><p><em>Thanks, for reading this till the end. I will be happy if it helps you at any point in your development process. </em><strong><em>I will be glad to help if you need any help in React and Ruby on Rails.</em></strong></p><p><a href="/service/mailto: akhilgautam123@gmail.com"><em>Akhil Gautam</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e45091849dd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authorize your React Components with Higher-Order Component]]></title>
            <link>https://akhilgautam.medium.com/authorize-your-react-components-with-higher-order-component-1a1c95c323e2?source=rss-5bc3502a936a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a1c95c323e2</guid>
            <category><![CDATA[học]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <category><![CDATA[front-end-authorization]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Akhil Gautam]]></dc:creator>
            <pubDate>Wed, 24 Apr 2019 17:25:10 GMT</pubDate>
            <atom:updated>2019-06-10T06:30:54.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZF8qDAogGFceXjiRLZd_Q.jpeg" /><figcaption>Courtesy: <a href="https://www.pexels.com/@wdnet">https://www.pexels.com/@wdnet</a></figcaption></figure><p><strong>Before we begin this, please assume the following:<br>- </strong>We will discuss about <em>A</em><strong><em>uthorization</em></strong> and not <strong><em>Authentication </em></strong>(<a href="https://medium.com/datadriveninvestor/authentication-vs-authorization-716fea914d55"><em>Authorization is not Authentication</em></a><em>).<br></em><strong>-</strong><em> </em>Our React App is storing <strong>Logged-In user’s Role</strong> in <strong>localStorage</strong>(you can put it anywhere in the browser).</p><p><strong>Let’s build the basement first… 🏃 🏃🏃🏃🏃</strong></p><ol><li><a href="https://reactjs.org/docs/higher-order-components.html"><strong>HOC (Higher-Order Component)</strong></a><strong>:<br></strong>The word sounds so cool 🆒 but it is little bit confusing as it’s not exactly a component but a <strong><em>function. ️</em></strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*zvOWgihoWHX0K5pKsjPkNA.jpeg" /></figure><p>You heard it right, Higher-Order Component is a function and not a component. Let me show you it’s definition:</p><blockquote><strong><em>A higher-order component is a function that takes a component and returns a new component.</em></strong></blockquote><p>HOCs are functions to which we pass our components and they can bring some transformation to it and return back a new component. If you have ever used <strong>Redux</strong> or <strong>Material-UI</strong>, you would have seen something like <strong>connect and withStyles. </strong>Connect and withStyles are HOCs which transforms our component and returns back a new component. If we talk specifically about <strong>connect</strong>, it injects props in our component which we name as <em>mapDispatchToProps</em> and <em>mapStateToProps</em>.<br>Did you just say something like <strong>map??? map </strong>can also be assumed as a HOC which takes an array and return a transformed array.</p><p>2. I assume you have basic knowledge of React, so let’s jump directly into Authorizing our React Components. Many a times, we have requirement to hide something from a normal user but show it to Admins. <em>This is what we call authorization, where we show different pages of our application to different types of users based on his/her role in our application.</em></p><p>Let’s say, we have a &lt;<strong>ServerMonitor /&gt; </strong>component which we don’t want to show to normal users and only to Admins. So we will create a HOC for authorizing our components to which we can pass any component we want to authorize.</p><blockquote><em>The HOC that we will build is </em><strong><em>withAuthorization </em></strong><em>which </em><strong><em>will take only one parameter, that is the component</em></strong><em> which we want to authorize.</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a1e450d4539ef8906fad31c51314a8d/href">https://medium.com/media/5a1e450d4539ef8906fad31c51314a8d/href</a></iframe><p>The <strong>withAuthorization</strong> HOC is not so fancy, it is just checking if the current_user is Admin, then <strong>allow the component to render</strong> else send <strong>null</strong> to prevent the component from rendering.</p><p><em>Next, we will see how to use </em><strong><em>withAuthorization</em></strong><em> in our React Components 👊👊</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/562e66ce9d4d1b94fb786481ac9953b8/href">https://medium.com/media/562e66ce9d4d1b94fb786481ac9953b8/href</a></iframe><p>Here in the above snippet, we are passing our <strong>ServerMonitor </strong>component to the <strong>withAuthorization </strong>HOC and exporting the returned value. If the current_user is an <em>admin </em>then the same component is returned and hence is exported else <strong>null</strong> is returned and exported which leads to preventing the <strong>ServerMonitor</strong> component from rendering in the DOM.</p><h3><strong>Caveat 😢 😢</strong></h3><p>Here we are authorizing the components based on UserRole stored in the localStorage which can be changed easily and can be replaced with <strong>Admin or anything. </strong>So we should have Authorization in our Back-end too in order to prevent data getting exposed to anyone trying to tamper the localStorage.</p><p>Thanks for reading it till the end. Hope it helped you and you enjoyed it. 😍 😍</p><p>If you need any help related to <strong>React, Ruby on Rails or Javascript</strong>, you can freely connect with me at <a href="http://mail_to:akhilgautam123@gmail.com/"><strong><em>akhilgautam123@gmail.com</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a1c95c323e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiple Hosting on Firebase with CircleCI]]></title>
            <link>https://medium.com/akhilgautam/multiple-hosting-on-firebase-with-circleci-c7d0f851f4e4?source=rss-5bc3502a936a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7d0f851f4e4</guid>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[multiple-hosting]]></category>
            <category><![CDATA[circleci]]></category>
            <dc:creator><![CDATA[Akhil Gautam]]></dc:creator>
            <pubDate>Sat, 17 Nov 2018 07:32:50 GMT</pubDate>
            <atom:updated>2018-12-19T11:59:44.655Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Ul9jJTDEI0WQTyc2yCehw.jpeg" /><figcaption>Credits: pexels.com</figcaption></figure><p><strong>[TL;DR]<br>I got headache and all kinds of pain while following Google’s documentation about Firebase.<br></strong>We had a requirement of deploying our static website pages anywhere but get it served over HTTPS. And like every smart developer 😝 I started searching for easiest way. We came across Firebase which automatically serves the websites over HTTPS. The joy was heavenly but… It didn’t last long. We followed their doc and we were stuck in the midway.<br><em>One thing I missed saying: we had multiple web-apps in the same codebase which added to our grief.</em></p><p><strong>But I am a smart developer </strong>😛<br>I started applying a hell lot of combinations in the firebase.json file but got no luck. Even when it worked from our local system, the circleCI was not able to do the same. But I am a <strong>Smart Developer 😫</strong>, I will try few more combinations and finally I got success.</p><p><strong>Spoon-feeding starts here..</strong>🎃<br><strong>1</strong>. We create an account on firebase or just login using our google account.<br><strong>2</strong>. We can create as many projects we want. Give some meaningfull name as the project’s name in smallcase is going to be your projectID. <br>If we set project name as <em>SomeWebApp</em> the projectID will be assigned <em>somewebapp</em> automatically.<br><strong>3</strong>. Install firebase tools in our local system to check if they are working.</p><pre>//installing firebase-tools globally<br>npm install -g firebase-tools</pre><pre>//then go to project dir<br>firebase login</pre><pre>//initiate it for you project<br>firebase init</pre><p><strong>4</strong>. After running the last command we have to select our firebase project that we are going to associate with our local project. It will ask for some default setup, just press Yes for all as we will be making changes manually.</p><p><strong>5</strong>. Now in our project we will be having a <em>firebase.json </em>file. Open it up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c327da47a2a81577daba6c221a418812/href">https://medium.com/media/c327da47a2a81577daba6c221a418812/href</a></iframe><p>The above configuration is specially for multiple hosting(or when the same codebase will be shared between different environments like staging and production). dist1 is the directory where our build for the first app is saved and dist2 is for the second one.</p><p><strong>6</strong>. Previously we had added only one firebase project to our local. Now its time to add all the projects. In the above case we have two apps in local, so we will be adding two firebase projects to our local. In our firebase account, we have two projects, viz. <em>projectone</em> and <em>projecttwo</em>.</p><pre>//make sure you have two projects in your firebase account<br>firebase use --add</pre><p>We will be selecting <em>projectone</em> first. Then it will ask for alias name, skip that.</p><pre>//then link the <em>projectone</em> of firebase to <em>appone</em> of local.<br>firebase target:apply hosting appone projectone</pre><pre>//now deploy appone<br>firebase deploy --only hosting:appone</pre><p>That’s it, your first app is deployed. Its build was fetched from the target_name that we gave on the above command because we have mapped the target_names with repective build directories in the firebase.json file.</p><p><strong>7</strong>. Do the same for the second app also.</p><pre>//add the second firebase project to local<br>//slect the project and skip adding alias<br>firebase use --add</pre><pre>//link the target with project<br>firebase target:apply hosting apptwo projecttwo</pre><pre>//deploy it<br>firebase deploy --only hosting:apptwo</pre><p><strong>That is it!!<br></strong>Following these we can easily deploy multiple projects from you local. But there is some thing we have to do everytime. We have to run <strong><em>firebase use project_name</em></strong> everytime before deploying to a specific project.<br>So <strong>-P </strong>option comes to our rescue now. We have change just a bit in our last deployment command.</p><pre>// for projectone<br>firebase deploy -P projectone --only hosting:appone</pre><pre>// for projecttwo<br>firebase deploy -P projectwo --only hosting:apptwo</pre><p><strong>Adding these to CircleCI </strong>😿 😢<br>Adding the above steps to circleCI pipeline might seem tedious but actually, its a dead simple task. We don’t need to add all the above steps to the CI pipe but only the deployment command. You might be thinking, how the ***k it will set the projects and all.<br>Lets rewind… Go to your project directory in local. You will find a .firebaserc file with some magical json schema. This is the file which you have to push with your codebase to you repo and it will do all the jobs for you because the firebase-cli reads project related information from this file.</p><p><strong>Spoon-feeding continues..<br>1</strong>. In our terminal, we type</p><pre>firebase login:ci</pre><pre>// after successfull login, it will give us our firebase_token.<br>// copy it from terminal and add it to our circleCI&#39;s environment<br>// variable</pre><p><strong>2</strong>. Our config.yml for circleCI:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3ee3308afc7eb28ef733e3e5862ad74/href">https://medium.com/media/f3ee3308afc7eb28ef733e3e5862ad74/href</a></iframe><p>And finally as we are <strong>💁 </strong>SMART DEVELOPERS, we can just <strong>ctrl+c/ctr+v</strong> all the above sinppets and it will work fine.</p><p><strong>Thanks if you have come all the way down. 😄 😅</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7d0f851f4e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/akhilgautam/multiple-hosting-on-firebase-with-circleci-c7d0f851f4e4">Multiple Hosting on Firebase with CircleCI</a> was originally published in <a href="https://medium.com/akhilgautam">akhilgautam</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>