<?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 Khushal Agarwal on Medium]]></title>
        <description><![CDATA[Stories by Khushal Agarwal on Medium]]></description>
        <link>https://medium.com/@khushal87?source=rss-d8ec6b66355a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*E1RvxXD33nOre89kilRJ7Q.png</url>
            <title>Stories by Khushal Agarwal on Medium</title>
            <link>https://medium.com/@khushal87?source=rss-d8ec6b66355a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 02:40:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khushal87/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[Google Summer of Code’21 — Khushal Agarwal]]></title>
            <link>https://khushal87.medium.com/google-summer-of-code21-khushal-agarwal-485c39ca2153?source=rss-d8ec6b66355a------2</link>
            <guid isPermaLink="false">https://medium.com/p/485c39ca2153</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[google-summer-of-code]]></category>
            <dc:creator><![CDATA[Khushal Agarwal]]></dc:creator>
            <pubDate>Tue, 31 Aug 2021 10:10:51 GMT</pubDate>
            <atom:updated>2021-08-31T14:00:02.033Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Summer of Code’21 — Khushal Agarwal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*TR1i3GQMnPiNRVVdm2Oj9Q.jpeg" /></figure><p>This summer, I was pleased to get selected for Google Summer of Code’21 under the organization [React Native Elements](<a href="https://github.com/react-native-elements">https://github.com/react-native-elements</a>). Working under the organization, my project was to **generate documentation automatically out of the UI components and present it in the Docusaurus website**.</p><p><a href="https://media.giphy.com/media/ZcKASxMYMKA9SQnhIl/giphy.gif">https://media.giphy.com/media/ZcKASxMYMKA9SQnhIl/giphy.gif</a></p><p>The purpose of creating this repository is to maintain a report summary of my GSoC work and this may also serve as a guide for future GSoC aspirants and a reference to the developers and contributors to the project.</p><p>## Project idea</p><p>#### [Automatically generate documentation out of React/React Native Component](<a href="https://summerofcode.withgoogle.com/projects/#5690075263795200">https://summerofcode.withgoogle.com/projects/#5690075263795200</a>)</p><p>## 📙 Abstract</p><p>[React Native Elements](<a href="https://www.npmjs.com/package/react-native-elements">https://www.npmjs.com/package/react-native-elements</a>) is a cross-platform UI toolkit built on/for React Native. With a weekly download by 90k+ users and backed by a huge community, it provides UI components that can be used in your native application for the platform of Android/iOS/Web.</p><p>The documentation of the project was maintained manually previously i.e., suppose I want to change/add/remove a prop or a new component to the project the markdown file had to be changed manually. The process is tiring and new contributors may often forget to do so. So, during the summers I took the change this process and make a workflow such that the generation is automatic. This should be **fast and maintainable**.</p><p>## 📝 Deliverables</p><p>The deliverables of the project are as follows:</p><p>- [x] Efficient Development Setup<br>- [x] Re-structure and Refactor code to have a common pattern.<br>- [x] Maintain the Usage/Examples of the component as they are needed to be updated manually.<br>- [x] Refactor and rename the directory structure such that Autogen is successful.<br> — Convert the code-base to have all the functional components.<br>- [x] Commenting on all the components and props.<br> — Adding descriptions.<br> — Adding prop descriptions.<br> — Ensuring a common pattern is followed.<br>- [x] Writing **scripts to extract data out**(in JS/TS) of it in the form of JSON.<br>- [x] Converting the JSON data to Markdown.<br>- [x] Automating the process such that the workflow works automatically whenever there is a change in the prop/definition or component code.</p><p>All of the listed deliverables were completed within the GSoC period. 🎉</p><p>## 📦 Working product</p><p>The work can be found here — [Official Website of React native elements](<a href="https://reactnativeelements.com/docs/next/">https://reactnativeelements.com/docs/next/</a>). Please refer to the component docs.</p><p>**I have also written a blog on how it works attached [here](<a href="https://reactnativeelements.com/blog/2021/08/12/auto-generation-of-docs).**">https://reactnativeelements.com/blog/2021/08/12/auto-generation-of-docs).**</a></p><p>## 🚀 Contributions</p><p>### Pull requests</p><p>| PR Link | Description | Status |<br>| — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — | — — — — — — — — — — — — — — — — — — — — — — — — — — — — | — — — — — |<br>| [#3071](<a href="https://github.com/react-native-elements/react-native-elements/pull/3071">https://github.com/react-native-elements/react-native-elements/pull/3071</a>) | [Refactor] Documentation directory structure | Merged ✅ |<br>| [#3081](<a href="https://github.com/react-native-elements/react-native-elements/pull/3081">https://github.com/react-native-elements/react-native-elements/pull/3081</a>) | [Refactor] Directory structure of components | Merged ✅ |<br>| [#3112](<a href="https://github.com/react-native-elements/react-native-elements/pull/3112">https://github.com/react-native-elements/react-native-elements/pull/3112</a>) | [Add] props description, descriptions to the component. | Merged ✅ |<br>| [#3126](<a href="https://github.com/react-native-elements/react-native-elements/pull/3126">https://github.com/react-native-elements/react-native-elements/pull/3126</a>) | [Docs] Added demos and snack for the documentation | Merged ✅ |<br>| [#3136](<a href="https://github.com/react-native-elements/react-native-elements/pull/3136">https://github.com/react-native-elements/react-native-elements/pull/3136</a>) | [Add] Docgen auto generation of docs scripts | Merged ✅ |<br>| [#3142](<a href="https://github.com/react-native-elements/react-native-elements/pull/3142">https://github.com/react-native-elements/react-native-elements/pull/3142</a>) | [Docs] Added generate-markdown scripts | Merged ✅ |<br>| [#3143](<a href="https://github.com/react-native-elements/react-native-elements/pull/3143">https://github.com/react-native-elements/react-native-elements/pull/3143</a>), [#3144](<a href="https://github.com/react-native-elements/react-native-elements/pull/3144">https://github.com/react-native-elements/react-native-elements/pull/3144</a>) | [Fix] Issues related to auto-generation of documentation | Merged ✅ |<br>| [#3145](<a href="https://github.com/react-native-elements/react-native-elements/pull/3145">https://github.com/react-native-elements/react-native-elements/pull/3145</a>) | [Fix, Improve] Doc-gen issues and automation | Merged ✅ |</p><p>### Issues</p><p>| Issue link | Description |<br>| — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — | — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — |<br>| [#3171](<a href="https://github.com/react-native-elements/react-native-elements/issues/3171">https://github.com/react-native-elements/react-native-elements/issues/3171</a>) | [Docs] Auto-generation of documentation for class based components |</p><p>Apart from these contributions, I have contributed to other React native elements projects. They can be summarized as:</p><p>- [Pull requests](<a href="https://github.com/pulls?q=is:pr+org:react-native-elements+author:khushal87">https://github.com/pulls?q=is:pr+org:react-native-elements+author:khushal87</a>)<br>- [Issues](<a href="https://github.com/issues?q=is:issue+org:react-native-elements+author:khushal87">https://github.com/issues?q=is:issue+org:react-native-elements+author:khushal87</a>)</p><p>| Project | Reference |<br>| — — — — — — — — — — — — — — — — — | — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — |<br>| React Native Elements — main repo | [Pull requests](<a href="https://github.com/react-native-elements/react-native-elements/pulls?q=is%3Apr+author%3Akhushal87+">https://github.com/react-native-elements/react-native-elements/pulls?q=is%3Apr+author%3Akhushal87+</a>) |<br>| React Native Elements App | [Pull requests](<a href="https://github.com/react-native-elements/react-native-elements-app/pulls?q=is%3Apr+author%3Akhushal87+is%3Aclosed">https://github.com/react-native-elements/react-native-elements-app/pulls?q=is%3Apr+author%3Akhushal87+is%3Aclosed</a>) |<br>| Playground | [Pull requests](<a href="https://github.com/react-native-elements/playground/pulls?q=is%3Apr+author%3Akhushal87+is%3Aclosed">https://github.com/react-native-elements/playground/pulls?q=is%3Apr+author%3Akhushal87+is%3Aclosed</a>) |</p><p>## 👨 Mentors</p><p>I would like to thank my mentors for helping me reach this milestone. 😄😄</p><p>I have not only learned about the Open Source culture and how to write good code but also, learned how the industry works and the import</p><p>- **Dhruvdutt Jadhav** — [GitHub](<a href="https://github.com/dhruvdutt">https://github.com/dhruvdutt</a>). [LinkedIn](<a href="https://www.linkedin.com/in/dhruvdutt-jadhav/">https://www.linkedin.com/in/dhruvdutt-jadhav/</a>)<br>- **Pranshu Chittora** — [GitHub](<a href="https://github.com/pranshuchittora">https://github.com/pranshuchittora</a>). [LinkedIn](<a href="https://www.linkedin.com/in/pranshuchittora/">https://www.linkedin.com/in/pranshuchittora/</a>)<br>- **Jeremy Hamilton** — [GitHub](<a href="https://github.com/flyingcircle">https://github.com/flyingcircle</a>). [LinkedIn](<a href="https://www.linkedin.com/in/jeremy-hamilton-19b6217b/">https://www.linkedin.com/in/jeremy-hamilton-19b6217b/</a>)</p><p>I would also like to thank [Arpit Bhalla](<a href="https://github.com/arpitBhalla">https://github.com/arpitBhalla</a>) for being an amazing partner in this amazing journey.</p><p>## 🔗 Links</p><p>&lt;div align=”center”&gt;</p><p>| **Student** | Khushal Agarwal |<br>| : — — — — — — — — | : — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — : |<br>| **Organization** | [React Native Elements](<a href="https://github.com/react-native-elements/">https://github.com/react-native-elements/</a>) |<br>| **Project** | [Automatically generate documentation from components](<a href="https://summerofcode.withgoogle.com/projects/#5690075263795200">https://summerofcode.withgoogle.com/projects/#5690075263795200</a>) |<br>| **GitHub** | [khushal87](<a href="https://github.com/khushal87">https://github.com/khushal87</a>) |<br>| **LinkedIn** | [Khushal Agarwal](<a href="https://www.linkedin.com/in/khushal87">https://www.linkedin.com/in/khushal87</a>) |<br>| **Twitter** | [khushal87](<a href="https://www.twitter.com/khushal87">https://www.twitter.com/khushal87</a>) |<br>| **Email** | &lt;a href=”<a href="/service/mailto:khushal.agarwal987@gmail.com">khushal.agarwal987@gmail.com</a>&quot;&gt;<a href="/service/mailto:khushal.agarwal987@gmail.com">khushal.agarwal987@gmail.com</a>&lt;/a&gt; |</p><p>&lt;/div&gt;</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=485c39ca2153" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linking a custom domain from Google domains to Vercel app]]></title>
            <link>https://khushal87.medium.com/linking-a-custom-domain-from-google-domains-to-vercel-app-961652302107?source=rss-d8ec6b66355a------2</link>
            <guid isPermaLink="false">https://medium.com/p/961652302107</guid>
            <category><![CDATA[domains]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Khushal Agarwal]]></dc:creator>
            <pubDate>Thu, 29 Apr 2021 18:55:39 GMT</pubDate>
            <atom:updated>2021-04-29T18:55:39.988Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRRkzisayx6RKspGUmryog.jpeg" /></figure><p>Linking a custom domain to a deployed application is confusing and at times you don’t get a route on how to link the domain with the website. 😫</p><p>In this article, I will be explaining how to link a <em>Custom domain brought in Google Domains service to an application hosted on Vercel</em>.</p><p>Perks of using Vercel is that it allows adding domain without any verification unlike Heroku/Netlify, which means you don’t have to add your billing details to add a domain to your application. Moreover, it is fast, efficient, and easy to use. 😁</p><h3>What is Vercel?</h3><blockquote><em>​Vercel is a deployment and collaboration platform for frontend developers. ​Vercel enables developers to host websites and web services that deploy instantly and scale automatically — all without any configuration. Source — </em><a href="https://vercel.com/docs"><em>Official Docs</em></a></blockquote><h3>What is Google Domain Service?</h3><blockquote><em>Google Domains is a domain name registrar operated by Google. Google Domains offers domain registration, DNS hosting, DNSSEC, Dynamic DNS, domain forwarding, and email forwarding. It also offers a one-click DNS configuration that connects the domains with Blogger, Google Sites, Squarespace, Weebly, and Shopify. Source — </em><a href="https://en.wikipedia.org/wiki/Google_Domains"><em>Wikipedia</em></a></blockquote><p>Without wasting much time, let us go deep on how to do it. 🤔</p><ul><li>Firstly, you need to make sure your application is deployed and running well on Vercel under the .vercel.app domain. Suppose your application name is xyz then the domain on which your application currently running would be xyz.vercel.app.</li><li>Go to the Settings section in your application workspace and then go to Domains. Under this section, you would see your domains which are currently linked with the application. You would also find the one mentioned above by default.</li><li>Type the custom domain that you have purchased from Google domains to the Input field in the View Domains section and add the domain.</li><li>A popup like the one below would appear and you would be asked to choose one of the options. You can choose any of the options among the 3 given ones. <em>Recommended</em> one is the first option, so we will choose that as we want our website to work on both xyz.com and ` <a href="http://www.xyz.com/">www.xyz.com</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/0*B9zUyFXgorPlQ2m9" /></figure><ul><li>Currently both the domains would show <em>Invalid configuration</em> and you need to configure them on the Google Domains Dashboard. So, let us do it.</li><li>Go to Google Domains Dashboard and choose your domain that you have purchased. Under, the domain workspace, go to the DNS option on the tab to the left of your screen.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/0*bQL5HAuccBSYED7e" /></figure><p>- Under the `DNS` section, scroll below and you would get the `Custom resource records` section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/0*XEWVm8k2k9Be318a" /></figure><ul><li>Now, we will add the A record for the domain xyz.com and CNAME record for the www.xyz.com as this has an alias www in it.</li><li>Copy the A record Value from your vercel domain section where you added your domain and add it to the Custom resource records. While adding it, leave the default name the same as @, Type as A, and TTL as 1h. Only add the IPv4 address which you copied from the Vercel Domain section. Click on Add.</li><li>Copy the CNAME record Value from the vercel domain section where you added your domain and add it to the Custom resource records. While adding it, make sure the Name is www, Type is CNAME, and leave TTL as 1h. Only add the Domain name value which you copied from the Vercel Domain section. Click on Add.</li><li>Once the above step is configured correctly, wait for some time and you will see Blue ticks under your domain configs in the Vercel dashboard. This means that the configuration and linking were successful and the domain would be linked to your application soon. 🎊 This may take time for some of the users because in general, the DNS propagation takes 24-48hrs. ⌚ But in my case, it hardly took 5 minutes. 😄</li><li>You can check whether your URL has propagated with this awesome tool <a href="https://dnschecker.org/">DNS Checker</a>.</li></ul><p>Kudos 👏👏 your domain is configured successfully and is linked to your Vercel app successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*wA56oSNJ0z1th0Ik" /></figure><h3>Follow and support me -</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRRkzisayx6RKspGUmryog.jpeg" /></figure><p>LinkedIn 👨‍💻 — <a href="https://www.linkedin.com/in/khushal87/">Khushal Agarwal</a></p><p><em>Originally published at </em><a href="https://gist.github.com/khushal87/81b7b74c4e5324b2ff29bbc51f059513"><em>http://github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=961652302107" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Authentication in React using React Context API — Part 2 (React Context API)]]></title>
            <link>https://khushal87.medium.com/implementing-authentication-in-react-using-react-context-api-part-2-react-context-api-f0c3d8e4d0e?source=rss-d8ec6b66355a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0c3d8e4d0e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[context-api]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Khushal Agarwal]]></dc:creator>
            <pubDate>Sun, 01 Nov 2020 08:05:34 GMT</pubDate>
            <atom:updated>2020-11-01T08:05:34.476Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing Authentication in React using React Context API — Part 2 (React Context API)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6C4nSvy2Woe0m7bWEn4BA.png" /></figure><p>Authentication 🔒 in frontend applications is always a daunting task for a beginner in ReactJS 🤔. One has to know the core concepts of ReactJS and well as how browser local storage, session storage etc. works in order to successfully implement the entire workflow behind authentication. Implementing it using Redux even adds more difficulty to the same. So, we will see how we can implement the same using the React Context API. Those who have no idea about what Context API is, we will look at the concept clearly on this article.</p><p>Note: There will be a series of 2–3 articles to give to the entire explaination on how this works.</p><p>Link to previous article — <a href="https://khushal87.hashnode.dev/implementing-authentication-in-react-using-react-context-api-part-1-react-context-api">Part 1</a></p><p>In the previous article, we learned the basics of React Context API such as how we initialize it, provide it to the component hierarchy and how we use it in a class based components.</p><p>Now the point is that how do we use it in a <strong>Function component</strong> 🤔?</p><p>Using function based component has several advantages as it allows using hooks, which we cannot use in a traditional class based component. Moreover, Function based approach comes out to be a boon for <strong>Context API</strong>. Also, we have a better performance in case of functional components compared to class based approach.</p><p>Well, let us see how? 🤗 In a traditional Stateful(class based) component, we can only use a single context under contextType which sometimes is not really friendly as we need multiple contexts at times for our state logic.</p><p>Eg. : Suppose, we have two contexts, one for <em>Auth</em>(used for storing user Auth info) and one for storing and providing <em>Client</em>’s data and we want to use them in a same component. What would be the scenario then?</p><p>Using stateful component won’t help here, as we could use only one context at a time. Though this is possible within the render function of the component using multiple Context Consumer. But this is not possible anywhere within the component.</p><p>You can find the Class based implementation <a href="https://khushal87.hashnode.dev/implementing-authentication-in-react-using-react-context-api-part-1-react-context-api">here</a>.</p><p>Now, Function based component gives us a flexibility of using both of them anywhere within the component.</p><p>Let us see how we use Context in a functional component.</p><h3>Function based Approach</h3><pre>import { useState } from &#39;react&#39;;<br>import { useAuthContext } from &#39;../Context/AuthContext&#39;;<br><br>function LoginScreen(props){<br>    const [mobile_number,setMobileNumber] = useState(&quot;&quot;);<br>    const [password,setPassword] = useState(&quot;&quot;);<br>    const {setToken , setData} = useAuthContext();<br><br>    const onSubmitHandler = (event) =&gt; {<br>        event.preventDefault();<br><br>        const params = {<br>            mobile_number: mobile_number,<br>            password: password<br>        }<br>        Axios.post(`/user/login`, params)<br>            .then((response) =&gt; {<br>                if (res.status === 200) {<br>                    setData(response.data.data);<br>                    setToken(response.data.token);<br>                }<br>            })<br>            .catch((err) =&gt; {<br>                console.log(error)<br>                Alert.alert(error.response.data.message);<br>            })<br>    }<br><br>    return (<br>        &lt;div className=&quot;login&quot;&gt;<br>            &lt;input<br>                type=&quot;text&quot;<br>                placeholder=&quot;Enter Mobile Number&quot;<br>                value={mobile_number}<br>                onChange={(event) =&gt; {<br>                    setMobileNumber(event.target.value)<br>                }}<br>            /&gt;<br>            &lt;input<br>                type=&quot;password&quot;<br>                placeholder=&quot;Enter Password&quot;<br>                value={password}<br>                onChange={(event) =&gt; {<br>                   setPassword(event.target.value)<br>                }}<br>            /&gt;<br>            &lt;button<br>                type=&quot;submit&quot;<br>                onClick={onSubmitHandler}&gt;<br>                Login<br>            &lt;/button&gt;<br>        &lt;/div&gt;<br>    )<br>}</pre><p>The difference mainly lies on how we use it. In the stateful component, we used contextType to use it globally within the component but here we take use of the custom <strong>Hook,</strong> useAuthContext which we created while initialization of the context. This way of implementing a component provides us the flexibility of using multiple hooks within a same component and thereby multiple Context in a same component.</p><p>Note: To understand how we implemented the <em>hook</em> for usage, refer to my previous blog.</p><p>In the code, we destructured the values of the context, simply through the hook as you see here in this snippet:</p><pre>const {setToken , setData} = useAuthContext();</pre><p>Now, we can use the destructured functions and data within our component. If we want to use multiple contexts, the approach would be entirely same.</p><p>Note: We also have the traditional way of consuming the context as was discussed in the previous blog using AuthContext.Consumer. This only allows using the Context within the return statement.</p><p>Comment down, which approach do you like to use on your projects. 😄😄</p><p>Kudos! Now, we are strong with the concept of **React Context API **. In the next blog we will see its application in Authentication. 😉😉</p><h3>Follow and support me -</h3><p>Github 👨‍💻— <a href="https://github.com/khushal87">khushal87</a></p><p>LinkedIn 👨‍💻 — <a href="https://www.linkedin.com/in/khushal-agarwal-547370166/">Khushal Agarwal</a></p><p>Portfolio — <a href="https://khushal87.github.io/Portfolio">Link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0c3d8e4d0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Authentication in React using React Context API — Part 1 (React Context API)]]></title>
            <link>https://khushal87.medium.com/implementing-authentication-in-react-using-react-context-api-part-1-react-context-api-6af552b72931?source=rss-d8ec6b66355a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6af552b72931</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Khushal Agarwal]]></dc:creator>
            <pubDate>Fri, 23 Oct 2020 05:57:09 GMT</pubDate>
            <atom:updated>2020-10-23T05:57:09.588Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing Authentication in React using React Context API — Part 1 (React Context API)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6C4nSvy2Woe0m7bWEn4BA.png" /></figure><p><strong>Authentication</strong>🔒 in frontend applications is always a daunting task for a beginner in ReactJS 🤔. One has to know the core concepts of ReactJS and well as how browser local storage, session storage etc. works in order to successfully implement the entire workflow behind authentication. Implementing it using Redux even adds more difficulty to the same. So, we will see how we can implement the same using the <strong>React Context API</strong>. Those who have no idea about what Context API is, we will look at the concept clearly on this <strong>article</strong>.</p><p><strong>Note:</strong> There will be a series of 2–3 articles to give to the entire explaination on how this works.</p><p>To start with, lets look at what Facebook says about it in there official docs:</p><blockquote><em>Context provides a way to pass data through the component tree without having to pass props down manually at every level.</em></blockquote><p>So, it is clear from the quote, that context API makes the data flow easier in applications. This can be used in small applications, or for using small functionalities like authentication, providing theme etc. in large applications.</p><p>Now, lets start with its working.</p><h3>Step 1 — Initialization</h3><pre>import React, { useContext } from &#39;react&#39;;<br><br>//Auth Context<br>export const AuthContext = React.createContext({<br>    token: null,<br>    setToken: (data) =&gt; { },<br>    data: null,<br>    setData: (data) =&gt; { },<br>})<br><br>//Use Auth Context<br>export function useAuthContext() {<br>    return useContext(AuthContext);<br>}</pre><p>A context is created using the concept, similar to this snippet of code. We pre-define our data and function which the context would serve in the application inside the createContext handler for its usage in other components and using this we serve the data when we need it.</p><h3>Step 2 — Providing the context to the component tree</h3><p>This is merely simple task, we first have to initialize the data we want to pass on in the context to our local state. Make sure we do it to a component at a lower level then that of its children i.e, where we want to actually use the context.</p><h4>Function based Approach</h4><pre>import { AuthContext } from &#39;../Context/AuthContext&#39;;<br><br>function App() {<br>    const [token, setToken] = useState(null);<br>    const [data, setData] = useState({});<br><br>    return (<br>        &lt;AuthContext.Provider<br>            value={{<br>                token: token,<br>                data: data,<br>                setToken: setToken,<br>                setData: setData,<br>            }}<br>        &gt;<br>          &lt;ChildComponents /&gt;<br>       &lt;/AuthContext.Provider&gt;<br>    );<br>}</pre><h4>Class based Approach</h4><pre>import { AuthContext } from &#39;../Context/AuthContext&#39;;<br><br>class App extends Component {<br>    constructor(props){<br>        super(props);<br>        this.state = {<br>            token : null,<br>            data : null<br>        }<br>    }<br><br>    setToken = (data)=&gt;{<br>        this.setState({ token : data });<br>    }<br><br>    setData = (data) =&gt;{<br>        this.setState({ data : data });<br>    }<br><br>    render() {<br>        return (<br>            &lt;AuthContext.Provider value = {{<br>                data : this.state.data,<br>                token : this.state.token,<br>                setToken : this.setToken,<br>                setData : this.setData<br>            }}&gt;<br>                &lt;ChildComponents /&gt;<br>            &lt;/AuthContext.Provider&gt;<br>        )<br>    }<br>}</pre><p>It is clear from the code snippet that we first initialize our local state of data which we pass on as value to the AuthContext.Provider.</p><p>* <strong>Note:</strong> We need to make sure that name of key inside the Context provider is same as that used during the initialization of the context.</p><p>React allows manipulation of the data inside functions if we want according to our business logic. This can be done by writing our own custom functions and then passing it in the Context provider value prop.</p><p>Now last, but not the least.</p><h3>Step 3 — Usage of Context</h3><p>There are two ways of using the context in a React component and the approach varies differently for a class based and function based components.</p><p>First lets discuss the way we use it in class based component. 👉</p><p>We have two ways of the same in a class based component, contextType and Context Consumer. The way I recommend and use myself is contextType. This way of using the context enables usage of the context everywhere in the component after the component is rendered.</p><blockquote><em>React will find the closest Context Provider above and use its value.</em></blockquote><pre>import { AuthContext } from &#39;../Context/AuthContext&#39;;<br><br>class LoginScreen extends Component {<br>    static contextType = AuthContext;<br>    constructor(props){<br>        super(props);<br>        this.state = {<br>            mobile_number:&quot;&quot;,<br>            password:&quot;&quot;<br>        }<br>    }<br><br>    onSubmitHandler = (event) =&gt; {<br>        event.preventDefault();<br>        const { setToken, setData } = this.context;<br><br>        const params = {<br>            mobile_number: this.state.mobile_number,<br>            password: this.state.password<br>        }<br>        Axios.post(`/user/login`, params)<br>            .then((response) =&gt; {<br>                if (res.status === 200) {<br>                    setData(response.data.data);<br>                    setToken(response.data.token);<br>                }<br>            })<br>            .catch((err) =&gt; {<br>                console.log(error)<br>                Alert.alert(error.response.data.message);<br>            })<br>    }<br><br>    render() {<br>        return (<br>            &lt;div className=&quot;login&quot;&gt;<br>                &lt;input<br>                    type=&quot;text&quot;<br>                    placeholder=&quot;Enter Mobile Number&quot;<br>                    value={this.state.mobile_number}<br>                    onChange={(event) =&gt; {<br>                this.setState({mobile_number:event.target.value})<br>                    }}<br>                /&gt;<br>                &lt;input<br>                    type=&quot;password&quot;<br>                    placeholder=&quot;Enter Password&quot;<br>                    value={this.state.password}<br>                    onChange={(event) =&gt; {<br>                        this.setState({password:event.target.value})<br>                    }}<br>                /&gt;<br>                &lt;button<br>                    type=&quot;submit&quot;<br>                    onClick={this.onSubmitHandler}&gt;<br>                    Login<br>                &lt;/button&gt;<br>            &lt;/div&gt;<br>        )<br>    }<br>}</pre><p>It is clear from the code when the button is clicked, the onSubmitHandler is executed and then the login API is called and after this we capture the response token and data in our context using the this.context. This makes the parent state capture the token and data and store inside the state of the component where the context was provided. Now this value can be used anywhere in our application, may it be for authentication i.e, by checking if the token is stored (using this.context.token) and logging in the user conditionally or displaying the data of the user any where. 🤗</p><p>* <strong>Note:</strong> To display the data we use this.context.data.name(example) etc.</p><p>The second approach used in the class based components is this:-</p><pre>import { AuthContext } from &#39;../Context/AuthContext&#39;;<br><br>class DisplayScreen extends Component {  <br>    render() {<br>        return (<br>            &lt;AuthContext.Consumer&gt;<br>                {value =&gt; (<br>                    &lt;div className=&quot;name&quot;&gt;{value.name}&lt;/div&gt;<br>                )}<br>            &lt;/AuthContext.Consumer&gt;<br>        )<br>    }<br>}</pre><p>This method has only one downfall i.e, it cannot be used anywhere within the class as we could do using the contextType.</p><p>P.S: The article is getting longer. we will see the functional approach of the same and authentication in the next article soon. Tune in for the same till then. Thank you ✌. I hope this was helpful, we will see more of it soon 😁</p><h3>Follow and support me -</h3><p>Github 👨‍💻 — <a href="https://github.com/khushal87">khushal87</a></p><p>LinkedIn 👨‍💻 — <a href="https://www.linkedin.com/in/khushal-agarwal-547370166/">Khushal Agarwal</a></p><p>Portfolio — <a href="https://khushal87.github.io/Portfolio">Link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6af552b72931" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gssoc’19  — A Whole New Experience For Me]]></title>
            <link>https://khushal87.medium.com/gssoc19-a-whole-new-experience-for-me-ffa4d1c84f4c?source=rss-d8ec6b66355a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffa4d1c84f4c</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[participation]]></category>
            <category><![CDATA[gssoc19]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Khushal Agarwal]]></dc:creator>
            <pubDate>Wed, 22 May 2019 12:08:13 GMT</pubDate>
            <atom:updated>2019-05-23T05:22:21.444Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gssoc’19 — A Whole New Experience For Me</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JAQrWx3nzgvPeZYop90PJQ.png" /><figcaption>Gssoc’19</figcaption></figure><h3>1) Participation</h3><p>I am a freshman to my college, and even to coding so I had no idea how would I perform on this sort of great open sourcing platform. But Gssoc’19, with its great platform of mentors,guides and a community with whole lot of developers and coders have been constantly guiding me through it.</p><h3>2) Choice of project</h3><p>As every selection do excite me, so did the Girlscirpt Summer Of Code. It was a whole new experience for me and the projects given by mentors here covered all the topics of native development. May it be Data structures and Algorithms or topics like Web Development,Mobile Application Development,Machine Learning and all the other such topic. Being a first year student I had little concept of all those topic but as participation is learning. I went through important topics like Data Structures and Algorithm, as well I had a good command on web development. So my selection of topics where on this projects. You can visit the github repo of the projects I contributed to here.</p><p><strong>Algo_Ds_Notes</strong></p><p><a href="https://github.com/jainaman224/Algo_Ds_Notes">jainaman224/Algo_Ds_Notes</a></p><p><strong>Connect-Me</strong></p><p><a href="https://github.com/fossasia/Connect-Me">fossasia/Connect-Me</a></p><p>Both the project let me contribute and learn a lot. I also had contributed to other projects and through it I had proper guidance.</p><h3>3) Experience</h3><p>Contributing in <em>“Algo_Ds_Notes”</em> I learnt the fundamental data structures as well as algorithms and this also helped me start with competitive coding. The mentor here was <strong><em>“Aman Jain”</em></strong>. He constantly guide me with github basics as well made me aware with the role of <strong>Github</strong> for the Open Sourcing. There where other mentors too who had always been beside us making us aware for healthy coding as well rules of proper open sourcing. Participating in it I had good command on github with experience in both terminal and UI. I also get to know some of the advanced topics such as squashing of commits on Github and also get to know the importance of a good code, with proper indentation and formatting.</p><h3>4) Community</h3><p>The community here was constantly active. I initially joined the <strong><em>slack</em></strong> channel of <strong>#gssoc19 </strong>and other channels of projects depending on my interests. The channels where highly active and had given constant support of all the mentors as well as the mentees. The <strong>#participants</strong> channel had over 990 members and dealt with individual doubts and queries. The <strong>#announcement </strong>channel had all the important announcements regarding how we need to go in this journey.</p><p>I celebrated when my first PR was merged and this confirmed me a certificate but my interest did not stop here and I continued with contributing to projects mainly <em>“Algo-Ds-Notes”</em> with constant support of mentors. All my errors and queries where effectively solved and now i stand at a good zone for future open sourcing. Till date I have 25+ PR’s merged on this journey and have learned a lot from this.</p><h3>5) Learnings</h3><p>Learnings from participating in #Gssoc19</p><ul><li><em>Opened up the world of Open Source — There are so many opportunities to contribute and learn just you have the zeal in participating.</em></li><li><em>Keep learning through mistakes. This is all Open Sourcing is.</em></li><li><em>Importance of being highly active in community</em></li></ul><blockquote>Therefore, Girlscript Summer of Code is a great zone for open sourcing and you learn a lot form it. The 3 months journey will soon come to an end but it will always be definately and experience worth rating high and now I feel I am highly obliged to participate in it.</blockquote><p>Signing off!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffa4d1c84f4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>