<?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 Arpitabiswal on Medium]]></title>
        <description><![CDATA[Stories by Arpitabiswal on Medium]]></description>
        <link>https://medium.com/@arpitabiswal777?source=rss-86f69215282d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Hvk31HP5wtzRhEn0.jpg</url>
            <title>Stories by Arpitabiswal on Medium</title>
            <link>https://medium.com/@arpitabiswal777?source=rss-86f69215282d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:34:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arpitabiswal777/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[JavaScript Throttling Explained: 3 Types, Timelines, Use Cases & Implementation]]></title>
            <link>https://medium.com/@arpitabiswal777/javascript-throttling-explained-3-types-timelines-use-cases-implementation-b8a98ad74bc9?source=rss-86f69215282d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8a98ad74bc9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[throttling]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <dc:creator><![CDATA[Arpitabiswal]]></dc:creator>
            <pubDate>Sun, 02 Aug 2026 05:25:06 GMT</pubDate>
            <atom:updated>2026-08-02T05:25:06.734Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this article we will discuss following:<br>1. What is Throttling?<br>2. Why do we need it?<br>3. Leading Edge Throttle<br>4. Trailing Edge Throttle<br>5. Leading + Trailing Throttle<br>6. Throttle vs Debounce<br>7. Quick Decision Table</h4><h3>1. What is Throttling ?</h3><p>Throttling limits how frequently a function can execute.</p><h3>2. Why do we need Throttling ?</h3><p>Benefits:<br> a) reduce excessive API calls<br> b) reduce unnecessary UI updates<br> c) reduce expensive calculations<br> d) improves perceived performance<br> e) makes interaction more smoother</p><h3><strong>3. Leading Edge Throttle:</strong></h3><p>A leading-edge <strong>throttle executes immediately on the first call</strong>. After that, subsequent calls during the throttle window are ignored.</p><pre>function leadingEdgeThrottle(fn, delay) {<br>    let isThrottled = false;<br><br>    return function (...args) {<br><br>        if (isThrottled) {<br>            return;<br>        }<br><br>        fn.apply(this,args)<br><br>        isThrottled = true;<br><br>        setTimeout(()=&gt;{<br>            isThrottled = false;<br>        },delay)<br><br>    };<br>}</pre><p><strong>Use Case: </strong>Instant feedback (e.g. button click ripple), but ignores rapid trailing changes</p><h3><strong>4. Trailing Edge Throttle</strong></h3><p>A trailing-edge throttle waits until the throttle window ends and <strong>executes the latest call.</strong></p><pre>function trailingEdgeThrottle(fn, delay) {<br>    let timer = null;<br>    let lastArgs;<br>    let lastThis;<br><br>    return function (...args) {<br>        lastArgs = args;<br>        lastThis = this;<br><br>        if (timer) return;<br><br>        timer = setTimeout(() =&gt; {<br>            fn.apply(lastThis,lastArgs);<br>            lastArgs = null;<br>            lastThis = null;<br>            timer = null;<br>        }, delay);<br>    };<br><br>}</pre><p><strong>Use Case:</strong> Scroll/resize/drag handlers where you care about “final settled state”</p><h3>5. Both Leading and Trailing Throttle</h3><p>Sometimes <strong>we need both:</strong><br>a) Execute immediately when event starts.<br>b) Execute the latest call at the end of throttle window.</p><pre>function bothLeadingAndTrailingThrottle(fn,delay){<br>  let timer = null;<br>  let lastArgs = null;<br>  let lastThis = null;<br>  <br>  return function(...args){<br>    lastArgs = args;<br>    lastThis = this;<br>    if(timer) return;<br>    // leading edge for first call<br>    fn.apply(lastThis, lastArgs);<br>    lastArgs = null;<br>    lastThis = null;<br>    // trailing edge , if there are further call within the window<br>    timer = setTimeout(() =&gt; {<br>      timer = null;<br>      if(lastArgs){<br>        fn.apply(lastThis, lastArgs);<br>        lastArgs = null;<br>        lastThis = null;<br>      }<br>    },delay)<br>  }<br>}</pre><p><strong>Use Case: </strong>Best UX generally — immediate response + doesn’t drop the final update. This is what <strong>Lodash (_.throttle())</strong> does by default.</p><p><strong>TimeLine chart:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZXuu3fWF8A_hsKAQTOGt9Q.png" /></figure><p><strong>Grey dots:</strong> Every call incoming in.<br><strong>Green dot:</strong> The moment fn actually runs.</p><h3><strong>6. Throttle vs Debounce</strong></h3><p><em>Throttle says:</em><br> Execute the event at controlled intervals. If delay is 500ms, then call back executes at every 500ms</p><p><em>Debounce says:</em><br> Execute the event once user action has stopped. If delay is 500ms, then callback executes after 500ms of user has last performed the action.</p><h3><strong>7. Quick Decision Table</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aHkQjdFe6kRFc-RGfGS33A.png" /></figure><p>Hope this article helped you to understand throttle in javascript. <br>Follow for more articles.😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8a98ad74bc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing React Context: The Power of Splitting Providers]]></title>
            <link>https://medium.com/@arpitabiswal777/optimizing-react-context-the-power-of-splitting-providers-e90685037410?source=rss-86f69215282d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e90685037410</guid>
            <category><![CDATA[react-context-api]]></category>
            <category><![CDATA[react-context]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <dc:creator><![CDATA[Arpitabiswal]]></dc:creator>
            <pubDate>Sun, 19 Apr 2026 08:12:43 GMT</pubDate>
            <atom:updated>2026-04-19T08:12:43.632Z</atom:updated>
            <content:encoded><![CDATA[<p>I will keep this exercise very simple and easy to understand.<br>We will understand it step wise.:<br> 1️⃣ Passing props<br> 2️⃣ using Context<br> 3️⃣ Splitting Context Providers</p><blockquote><strong>UI Overview: </strong><br> Page Component that wraps our entire JSX.<br> The Left side is a Sidebar. It has a expand/collapse button. <br> Right side is Main area : a top area with HeavyComponent and bottom area. Bottom Area has. two/three sections, depending on if Sidebar is expanded/collapsed respectively.</blockquote><h3>🔴 <strong>Props — Causing Unnecessary Re-renders.</strong></h3><pre>const Page = () =&gt; {<br>  const [isOpen, setIsOpen] = useState(false);<br>  const toggleOpen = () =&gt; setIsOpen((prev) =&gt; !prev);<br>  return (<br>    &lt;Layout&gt;<br>      &lt;SideBar isOpen={isOpen} toggleOpen={toggleOpen} /&gt;<br>      &lt;Main isOpen={isOpen} /&gt;<br>    &lt;/Layout&gt;<br>  );<br>};<br><br>const Main = ({ isOpen }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;HeavyComponent /&gt;<br>      &lt;AdjustableBlock isOpen={isOpen} /&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>const SideBar = ({ isOpen, toggleOpen }) =&gt; {<br>  return (<br>    &lt;div style={{ background: &#39;#ccc&#39;, width: isOpen ? &#39;200px&#39; : &#39;50px&#39; }}&gt;<br>      &lt;ActionButttons toggleOpen={toggleOpen} /&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><p>👉 The Problem:<br> isOpen is only actually used in <strong>SideBar</strong> and <strong>AdjustableBlock</strong> component<strong>.<br> </strong>But when it changes:<br>❗ Child re-renders <br>❗Page,Layout,Main,HeavyComponent,ActionButtons also re-renders (unnecessary)</p><h3>🟡 <strong>Context — Partial Improvement</strong></h3><pre>const NavigationContext = createContext({});<br><br>export function NavigationController({ children }) {<br>  const [isOpen, setIsOpen] = useState(false);<br><br>  const open = useCallback(() =&gt; setIsOpen(true), []);<br>  const close = useCallback(() =&gt; setIsOpen(false), []);<br><br>  const value = useMemo(() =&gt; ({ isOpen, close, open }), [isOpen, open, close]);<br><br>  return (<br>    &lt;NavigationContext.Provider value={value}&gt;<br>      {children}<br>    &lt;/NavigationContext.Provider&gt;<br>  );<br>}<br><br>export function useNavigationContext() {<br>  return useContext(NavigationContext);<br>}<br><br>const Page = () =&gt; {<br>  return (<br>    &lt;NavigationController&gt;<br>      &lt;Layout&gt;<br>        &lt;SideBar /&gt;<br>        &lt;Main /&gt;<br>      &lt;/Layout&gt;<br>    &lt;/NavigationController&gt;<br>  );<br>};<br><br>const SideBar = () =&gt; {<br>  const { isOpen } = useNavigationContext();  // using context now rather than props<br>  /* rest of the code */<br>};<br><br>const AdjustableBlock = () =&gt; {<br>  const { isOpen } = useNavigationContext(); // using context now rather than props<br>  /* rest of the code */<br>};<br><br>const ActionButtons = () =&gt; {<br>  const { open, close } = useNavigationContext();  // using context now rather than props<br>  /* rest of the code */<br>};</pre><p>Improvement:<br>- Now on each toggle<br> ✅ Only <strong>SideBar</strong>, <strong>AdjustableBlock</strong>, <strong>ActionButtons</strong> component re-renders<br> ✅ <strong>Page</strong>,<strong>Layout</strong>,<strong>Main,HeavyComponent</strong> no more re-renders<br> ❗️<strong>ActionButtons </strong>re-renders , even though it does not consumes <em>isOpen</em><br> from context</p><h3>🟢 <strong>Split Providers — The Real Optimization</strong></h3><h4>👉 Separate <strong>data</strong> and <strong>actions</strong></h4><pre>const NavigationDataContext = createContext({});<br>const NavigationApiContext = createContext({});<br><br>export function NavigationController({ children }) {<br>  const [isOpen, setIsOpen] = useState(false);<br><br>  const open = useCallback(() =&gt; setIsOpen(true), []);<br>  const close = useCallback(() =&gt; setIsOpen(false), []);<br><br>  const data = useMemo(() =&gt; ({ isOpen }), [isOpen]);<br>  const api = useMemo(() =&gt; ({ open, close }), [open, close]);<br><br>  return (<br>    &lt;NavigationDataContext.Provider value={data}&gt;<br>      &lt;NavigationApiContext.Provider value={api}&gt;<br>        {children}<br>      &lt;/NavigationApiContext.Provider&gt;<br>    &lt;/NavigationDataContext.Provider&gt;<br>  );<br>}<br><br>export function useNavigationDataContext() {<br>  return useContext(NavigationDataContext);<br>}<br><br>export function useNavigationApiContext() {<br>  return useContext(NavigationApiContext);<br>}<br><br>const SideBar = () =&gt; {<br>  const { isOpen } = useNavigationDataContext();  // using context now rather than props<br>  /* rest of the code */<br>};<br><br>const AdjustableBlock = () =&gt; {<br>  const { isOpen } = useNavigationDataContext(); // using context now rather than props<br>  /* rest of the code */<br>};<br><br>const ActionButtons = () =&gt; {<br>  const { open, close } = useNavigationApiContext();  // using context now rather than props<br>  /* rest of the code */<br>};</pre><h3>🎯 Result</h3><p>Now:<br> ✅ Components using isOpen → re-render (<strong>SideBar</strong> and <strong>AdjustableBlock</strong> )<br> ✅ Components using only open/close → ❌ no re-render</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZDxD-MhWcZfZBDFzvCEOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwNQ_Qj7HZ9IO_8uwU07qw.png" /></figure><p>Hope this helps. Do not forget to clap if you find this helpful. 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e90685037410" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Before You Optimize React, Read This (Memoization Made Simple)]]></title>
            <link>https://medium.com/@arpitabiswal777/before-you-optimize-react-read-this-memoization-made-simple-3949f30364a8?source=rss-86f69215282d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3949f30364a8</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Arpitabiswal]]></dc:creator>
            <pubDate>Sun, 05 Oct 2025 07:49:19 GMT</pubDate>
            <atom:updated>2025-10-05T07:49:19.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="“A creative illustration representing React memoization — highlighting when and where to use React.memo and useCallback effectively.”" src="https://cdn-images-1.medium.com/max/1024/1*thq1j5hW_f8t74tCv6_sug.png" /></figure><p>In this blog, you will learn about <br> 🚀 <strong><em>When not to to use memoization</em></strong><br> 🚀 <strong><em>Where to actually use them</em></strong><br> 🚀 <strong><em>Understanding React.memo != magic!</em></strong><br> 🚀 <strong><em>And some additional bonus part </em></strong>😋</p><h3>‼️ <strong>Do NOT always memoize your function</strong></h3><p>Look at the example below, where memoizing the function is useless. It re-renders your component anyways 😒</p><pre>const ComponentA = () =&gt; {<br>  const [count, setCount] = useState(0);<br>  const onClick = useCallback(() =&gt; {<br>    setCount((prevVal) =&gt; prevVal + 1);<br>  }, []);<br>  return (<br>    &lt;&gt;<br>      Current count is: {count}<br>      &lt;ComponentB onClick={onClick} /&gt;<br>    &lt;/&gt;<br>  );<br>};<br><br>const ComponentB = (props) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      Click me to increment count --{&#39; &#39;}<br>      &lt;button onClick={props.onClick}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;ComponentA /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Even though you’re memoizing onClick, <strong>ComponentA re-renders every time </strong><strong>count changes</strong> (since you’re updating state). And when a parent re-renders, its children (ComponentB) re-render <strong>too.</strong></p><h3><strong>Place where memoizing your props actually make sense</strong> 🚀🚀</h3><p><strong>(a) props as dependencies in any of the hooks.🪝</strong></p><p>Look at the code below where we are passing props to the child component where it is consumed in its hooks dependencies.</p><pre>const Parent = () =&gt; {<br>  const [count, setCount] = useState(0);<br>  const fetch = () =&gt; {<br>    console.log(&#39;Fetching some data...&#39;);<br>  };<br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; setCount((prev) =&gt; prev + 1)}&gt;<br>        Click Me! {count}<br>      &lt;/button&gt;<br>      &lt;Child onMount={fetch} /&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>const Child= ({ onMount }) =&gt; {<br>  useEffect(() =&gt; {<br>    onMount();<br>  }, [onMount]);<br><br>  return &lt;div&gt;Hello World!&lt;/div&gt;;<br>};<br><br>export default function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Parent /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>At first glance, everything seems correct! — Parent passes a function fetch to Child, and Child calls it when it mounts.</p><p>⚠️ <strong>The Problem:</strong> Even though the logic of fetch remains identical, at every state change of Parent it triggers the side effects in Child unnecessarily.</p><blockquote>Why ?<br> 👉 Every re-render of Parent creates a new fetch , hence new reference<br> 👉 Since onMount’s reference changes, the dependency [onMount] changes<br> 👉 This causes the useEffect inside Child to <strong>run again</strong> unnecessarily.</blockquote><p>✅ <strong>useCallback </strong>comes to the rescue 🛟<br>Memoizing your fetch inside a useCallback will save us from those unnecessary calls to useEffect .</p><p><strong>(b)</strong> <strong>component is wrapped in <em>React.memo. 📋</em></strong></p><p>Look at the example below, where child is wrapped inside React.memo but , it does not stop it from re-rendering.</p><pre>const ComponentA = () =&gt; {<br>  const [count, setCount] = useState(0);<br>  const onClick = () =&gt; {<br>    setCount((prevVal) =&gt; prevVal + 1);<br>  };<br><br>  return (<br>    &lt;&gt;<br>      Current count is: {count}<br>      &lt;button onClick={onClick}&gt;Click me&lt;/button&gt;<br>      &lt;ComponentB data={{ value: &#39;Hello&#39; }} /&gt;<br>    &lt;/&gt;<br>  );<br>};<br><br>const ComponentB = React.memo(({ data }) =&gt; {<br>  return &lt;div&gt;{data.value}&lt;/div&gt;;<br>});<br>export default ComponentB;<br><br>export default function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;ComponentA /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>⚠️ <strong>The Problem:</strong> You are passing <strong>new reference</strong> to ComponentB on every re-<br> render<br> data={{ value: &quot;Hello&quot; }} → new object created each time.</p><p>Hence:<br>prevProps.data !== nextProps.data<br>prevProps.onChange !== nextProps.onChange</p><p>💥 So React.memo re-renders every single time!</p><p>✅ <strong>useMemo </strong>comes to the rescue 🛟<br> Wrapping our data inside useMemo will serve the purpose of React.memo</p><pre>const data = useMemo(() =&gt; ({ value: &#39;Hello&#39; }), []);</pre><p>React.memo doesn’t stop re-renders — stable <strong>references</strong> do. 🔥</p><p>Now that we have learnt how these fancy React.memo , useCallback , useMemo if not used properly completely breaks their purpose.</p><p>Let me tell you one bonus point! 😋</p><p><strong>( c ) Children props <br> </strong>Look at the example below, where memoization is broken by children.</p><pre><br>const ComponentB = React.memo(({ children }) =&gt; {<br>  return &lt;div&gt;{children}&lt;/div&gt;;<br>});<br><br>const ComponentA = () =&gt; {<br>  return (<br>    &lt;ComponentB&gt;<br>      &lt;div&gt;Hello World&lt;/div&gt;<br>    &lt;/ComponentB&gt;<br>  );<br>};<br><br>export default ComponentA;</pre><p>The div wrapped inside ChildMemo is nothing but the children <strong>props.<br></strong>which can be re-written as:</p><pre>&lt;ChildMemo children={&lt;div&gt;Hello World&lt;/div&gt;}</pre><p>As our previous example, here also memoization breaks for same reason.<br>And they <strong>(children props) need to stabilised through useMemo as any other prop.</strong> We should not fall for the syntactical sugar. 🍭</p><blockquote>Memoization isn’t about using useCallback or React.memo everywhere — it’s about knowing <em>when not to</em>.<br> Keep your components simple, and optimize only when needed. ⚡</blockquote><blockquote>If you found it useful, <strong>give it a clap and share it with your dev friends!</strong> 🙌</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3949f30364a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>