<?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 Shailendra Kanherkar on Medium]]></title>
        <description><![CDATA[Stories by Shailendra Kanherkar on Medium]]></description>
        <link>https://medium.com/@shailendrakanherkar?source=rss-e621a904bcf7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Jbh2k3rCh0O_Dc88wZJSLQ.png</url>
            <title>Stories by Shailendra Kanherkar on Medium</title>
            <link>https://medium.com/@shailendrakanherkar?source=rss-e621a904bcf7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:26:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shailendrakanherkar/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[Can Recoil replace Redux ? State management in React.]]></title>
            <link>https://shailendrakanherkar.medium.com/can-recoil-replace-redux-state-management-in-react-3bf43a57a34d?source=rss-e621a904bcf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bf43a57a34d</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[recoil]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Shailendra Kanherkar]]></dc:creator>
            <pubDate>Wed, 27 Oct 2021 10:02:16 GMT</pubDate>
            <atom:updated>2021-10-27T10:02:16.032Z</atom:updated>
            <content:encoded><![CDATA[<h3>Can Recoil replace Redux ? State management in React.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zmNNvHC1TXBmgb2FHqqrbg.png" /></figure><p>Before we walk down to theory, We have <a href="https://github.com/shailendrakanherkar18/redux_vs_recoil">Repo</a> out with demo to show the difference between Recoil&amp;Redux. Also try running application to see how new features from Recoil makes a difference.</p><p><strong>Performance<br> </strong>Recoil subscriptions are on atom/selector updaters, while in Redux are on all actions. So if you have N connected component and dispatch an action that should trigger only one component, even if re-render is stopped by useSelector optimization, redux have to execute N subscription callbacks.</p><p><strong>Boilerplate code</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kPZWbcr6S4GHNk3NKNpdgQ.png" /></figure><p>You could have less than 5x boilerplate with redux, with many wrappers like RTK or redux-query, but even that you will write less code more powerful witn recoil. Set(atom, value), Execute Task are much more easy concepts to managed with , than dispatch, actions, reducers, sagas, etc…<br>I have created a <a href="https://github.com/shailendrakanherkar18/redux_vs_recoil">repo </a>to highlight the difference.</p><p><strong>Learning curve</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*XFHZ4FoylAuIuPY2nxJtDQ.jpeg" /></figure><p>High in Redux as Recoil follows the React principles so Recoil has less learning curve involve, In Redux we need understand the flow for updating state with the help of actions and need to get hang of end to end flow as well as show in below diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*UCyh4dnZxJ25wDaT" /></figure><p><strong>Async Support<br></strong>In Redux we can connect use <a href="https://redux-saga.js.org/">redux-saga</a> to achieve async support to separate the api calling mechanism within React application.<br>In Recoil we have mechanism to handle async internally where I found it really interesting with the help of selectors<br>You can checkout with <a href="https://github.com/shailendrakanherkar18/redux_vs_recoil/blob/master/src/users-recoil/recoil-state/selectors.js">repo</a> for more understanding.</p><p><strong>State<br></strong>We have global store in Redux, Everything is stored in store which is really performant where as Recoil provides a individually subscrible/changebal unit of state with atoms and selectors. Recoil states using 10,000 atoms are also very performant.<br>source : <a href="https://recoiljs.org/blog#scaling-to-large-numbers-of-atoms">https://recoiljs.org/blog#scaling-to-large-numbers-of-atoms</a></p><p><strong>Middleware</strong><br>Redux comes with the support of middleware such as redux-thunk/redux-saga. Which separates the api calling mechanism from application easily testable. Recoil internally handles many things for handling loading state while calling api which is used for showing loader till data is fetching. Also for async operation we can use selectors which is very robust.</p><p><strong>Memorized</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*FapDgYzK8aefw6lWzkfVbQ.jpeg" /></figure><p>Caching can be handled using <a href="https://github.com/reduxjs/reselect">re-select</a> library for Redux state, Reselect cache the output against the input provided to it. If we have addition function and we are calling it with parameter 3,5 it will return 8, Next time if you call same function with 3,5 it will not re-compute the value it will returned the cached value, Which is handled internally in Recoil. You don’t need any third party library for this.<br>Within our <a href="https://github.com/shailendrakanherkar18/redux_vs_recoil/blob/master/src/users-recoil/recoil-state/selectors.js">repo</a> when we try to call api from async selector, It will call only first mounted component later on it will return the cached value.</p><p><strong>Conclusion<br></strong>Recoil is still in experimental phase and we can track it <a href="https://recoiljs.org/blog">here</a>. Where as Redux is much stable state. Whereas considering experimental phase still used by many developers as well as by Facebook in production, I think it can replace. What do you think? Please share your thoughts via comments.</p><p><strong>Useful Links</strong> <br>1. <a href="https://github.com/shailendrakanherkar18/redux_vs_recoil">Repository</a></p><p>2. <a href="https://recoiljs.org/docs/introduction/installation/">Recoil Setup</a></p><p>3. <a href="https://recoiljs.org/blog">Recoil Track releases</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bf43a57a34d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recoil — useState vs useRecoilState]]></title>
            <link>https://shailendrakanherkar.medium.com/recoil-usestate-vs-userecoilstate-ac7cacd284c2?source=rss-e621a904bcf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac7cacd284c2</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Shailendra Kanherkar]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 14:16:38 GMT</pubDate>
            <atom:updated>2021-08-03T14:16:38.426Z</atom:updated>
            <content:encoded><![CDATA[<h3>Recoil — useState vs useRecoilState</h3><p>In this blog we will see useRecoilState hook from new library Recoil - by Facebook, How is it the new hook so Reactish?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7qf7lRoeEyKU6kE0qx2eg.png" /></figure><p><a href="https://recoiljs.org/">Recoil</a> is a new state management library for React, Manage global/sharable state in a Reactish way.</p><p><strong>Let’s take a very simple problem statement.<br></strong>We want to share the count state variable within two siblings/parallel children components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*W4IXyPP_uj87ye4ewE0arQ.png" /></figure><figure><img alt="React component with use State" src="https://cdn-images-1.medium.com/max/836/1*fmIoPrzVMxJNrKk1vmpaPw.png" /></figure><p><strong>First Solution</strong><br>The simplest possible solution would be moving state at parent level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WTvby1UHfhjWusoimJii3A.png" /></figure><p>This solves our problem but it will lead to below issues</p><ul><li>Here we have two level tree, But what if we have more than 5 level tree, It will lead to <strong>prop-drilling</strong> issues.</li><li>Component tree re-rendering.</li><li>Parent component will be overloaded with state and again lead to unnecessary re-renders.</li></ul><p><strong>Second Solution<br></strong>We can make use of context API from React. Context provides a way to pass data through the component tree without having to pass down manually at every level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5YHPKURRec4Ufh6IdeS2Ag.png" /></figure><p>We need to wrap parent component within Context provider and Child components (c1&amp;c2) can subscribe for it. Context gives benefits for avoiding <strong>prop-drilling.</strong><br>Few Limitation for context api:</p><ul><li>Multi-Context by module — Context can only share a single value, Not an indefinite set of values each with its own consumers.</li><li>Complex unit test cases — Need to create a copy component to write unit test cases.</li><li>Re-rendering each component.</li></ul><p><strong>Third Solution<br></strong>Finally I will introduce the useRecoilState, Where we can easily achieve this by creating sharable subscriber unit of state using <strong>atoms.</strong> To take benefits of Recoil api we need to wrap parent component with <strong>RecoilRoot.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*82p0omCjSBUNApjGsGgDyQ.png" /></figure><p>Below code will explain to us why Recoil is called Reactish and Minimal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6kScK4RJSKJBUlVfunDwSw.png" /></figure><p>Actually I am trying to compare useState and useRecoilState just to show how Reactish Recoil is, Recoil can be compared with other state management libraries like Redux,MobX, Apollo GraphQL etc.</p><p>Conclusion : Recoil is still in experimental phase; <a href="https://recoiljs.org/blog">But it is progressing faster</a>.</p><p>Extra reading :</p><ul><li><a href="https://recoiljs.org/docs/introduction/motivation">Recoil Documentation</a></li><li><a href="https://www.youtube.com/watch?v=_ISAA_Jt9kI">Recoil: State Management for Today’s React — Dave McCabe at @ReactEurope 2020</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac7cacd284c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding gotchas with un-mounting using useEffect hook— React]]></title>
            <link>https://shailendrakanherkar.medium.com/understanding-gotchas-with-un-mounting-using-useeffect-hook-react-b29c3f100ba6?source=rss-e621a904bcf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b29c3f100ba6</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[react-component-lifecycle]]></category>
            <category><![CDATA[functional-component]]></category>
            <dc:creator><![CDATA[Shailendra Kanherkar]]></dc:creator>
            <pubDate>Wed, 19 May 2021 17:49:20 GMT</pubDate>
            <atom:updated>2021-05-19T17:49:20.841Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog will clear the confusion between side-effects inside useEffect and handling componentWillUnmount lifecycle method in functional component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MTqDNj80g3tch4CAXPEHeA.jpeg" /></figure><p>In 2021, I can say many developers are loving the functional components implementation with the help of hooks.</p><p>Recently in one of my project while implementing Unmount lifecycle method using useEffect we faced issue like our unmount(return function inside useEffect) was getting executed where as component was still in mounted phase, While solving it I got few new learnings which I believe many people might not be aware of.</p><p>let’s begin,</p><p><strong>useEffect</strong><br>If you’re familiar with React class lifecycle methods, you can think of useEffectHook as componentDidMount, componentDidUpdate, and componentWillUnmount combined.</p><blockquote>function useEffect(effect: EffectCallback, deps?: DependencyList): void;</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H0eBeDihHAFnVDkFCPANIw.png" /></figure><p>useEffectaccepts two parameters, First as callback function which executes at time of mounting. Second is dependency array, If provided it executes a callback function if any of the value from dependency array is modified.</p><p>Let’s understand the typical usage of useEffect from above code snippet.</p><ul><li>Api call for fetching data from server and saving it over reducer (componentDidMount).</li><li>Having dependency of filter (componentDidUpdate).</li><li>On unmount clear the reducer(componentWillUnmount).</li></ul><p><strong>Assumption </strong>We assume like resetUserAction will be only dispatched when the component is unmounted right ??? That’s not the case.</p><p>Let me walk you through the exact problem statement.</p><p>I was dispatching an action on-mount which was listened to by Reducer(for turning on spinner)and by Saga(for calling an Api on success/failure and updating the reducer). Lets see the actual code for getting better arms on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z96ECK7I2uLN8g0tvhAOcQ.png" /></figure><p><em>Let’s dry run the above code.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDZYIpM0MZ56geTCDGgsLw.png" /></figure><blockquote>useEffect executes the callback function passed to it on initial mount and on every update i.e if any value from dependency array is updated e.g if filter is updated with actual filter value then it will re-execute the useEffect as well as componentWillUnmount i.e it will run the side-effect for clearing it.</blockquote><p><strong>Conclusion</strong> If we have a dependency array provided as dependency to useEffect then in that case useEffect will re-execute, If values from dependency array are updated as well as it will execute componentWillUnmount for clearing sideEffects.</p><p>useEffect with dependency array will run a returned function from it for clearing <strong>side-effects</strong>.</p><p>Useeffect having a dependency array empty will run the returned function as <strong>componentWillUnmount</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VxT9XqBX_MwefYAgzL6RAA.png" /></figure><p>Now it will run as expected only when the component is unmounted then only it will run the componentWillUnmount i.e will execute the return function defined inside new useEffect.</p><p>I faced a similar issue and spent some quality time understanding this flow. So I thought of sharing. Be careful while using useEffectwith dependency array.</p><p>If you find this useful please share with your colleagues/friends and please take a moment to provide your feedback in the form of comments below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b29c3f100ba6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>