<?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 Shivanggarg on Medium]]></title>
        <description><![CDATA[Stories by Shivanggarg on Medium]]></description>
        <link>https://medium.com/@shivanggarg48?source=rss-5660abefc278------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XLZaC_NrwSxawsfL</url>
            <title>Stories by Shivanggarg on Medium</title>
            <link>https://medium.com/@shivanggarg48?source=rss-5660abefc278------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 10:56:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivanggarg48/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[Reels scrolling optimization in ott platform]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-link"><a href="https://medium.com/@shivanggarg48/reels-scrolling-optimization-in-ott-platform-5d7fe9557774?source=rss-5660abefc278------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@shivanggarg48/reels-scrolling-optimization-in-ott-platform-5d7fe9557774?source=rss-5660abefc278------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d7fe9557774</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[gen-ai-course]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[gen-ai-adoption]]></category>
            <dc:creator><![CDATA[Shivanggarg]]></dc:creator>
            <pubDate>Fri, 08 May 2026 17:21:21 GMT</pubDate>
            <atom:updated>2026-05-08T17:21:21.793Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[NextTick in vue.js for beginners]]></title>
            <link>https://medium.com/@shivanggarg48/nexttick-in-vue-js-for-beginners-51b54d60f15a?source=rss-5660abefc278------2</link>
            <guid isPermaLink="false">https://medium.com/p/51b54d60f15a</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <dc:creator><![CDATA[Shivanggarg]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 16:31:48 GMT</pubDate>
            <atom:updated>2024-09-18T16:32:42.998Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*27pQjEB0CzABknGU.jpeg" /></figure><p>It is a useful feature provided by <strong>vue.js</strong>. The nextTick() method is used to call the callback function after the next update cycle of the <strong>DOM</strong>. It synchronises the <strong>DOM</strong> changes basically.</p><h4><strong>nextTick() description</strong></h4><p>When you modify the Vue component’s data (props or state) of a component in <strong>Vue.js</strong>, the DOM is not immediately updated. Instead, <strong>Vue.js</strong> updates the DOM asynchronously in the next tick of the event loop. This means that if you try to access the DOM immediately after modifying the data, the DOM may not be updated yet. It has higher priority than other callbacks after the DOM update.</p><h4><strong>How to use nextTick()</strong></h4><h4>1. nextTick()</h4><p>When changing Vue component data the DOM is updated asynchronously. Vue collects multiple updates to the virtual DOM from all the components, and then creates a single batch to update the DOM.</p><p>Updating DOM in a single batch is more performant than doing multiple small updates.</p><pre>&lt;script&gt;<br>import { ref, nextTick } from &#39;vue&#39;<br>const show = ref(true)<br>const content = ref()<br>const handleClick = () =&gt; {<br>  show.value = !show.value<br>  nextTick(() =&gt; {<br>    //call api which depend upon this.show<br>    //made changes to any state <br> })<br>}<br>&lt;/script&gt;<br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;button @click=&quot;handleClick&quot;&gt;Insert/Remove&lt;/button&gt;<br>    &lt;div v-if=&quot;show&quot; ref=&quot;content&quot;&gt;I am an content&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>You’d see that content is null or contains an element in exact correspondence with show value.</p><p>Also, nextTick(callback) executes the callback when all children components updates have been submitted to DOM.</p><p>There’s also this.$nextTick(callback) available on the component instance, which you might find useful in the case of options API.</p><h4>2. nextTick() with async/await</h4><p>If nextTick() is called without arguments, then the function return a promise that resolves when component data changes reach DOM.</p><p>That helps leverage the more readable async/await syntax.</p><pre>&lt;script&gt;<br>import { ref, nextTick } from &#39;vue&#39;<br>const show = ref(true)<br>const content = ref()<br>const handleClick = async () =&gt; {<br>  show.value = !show.value<br>  await nextTick()<br>  //call api which depend upon this.show<br>  //made changes to any state<br>}<br>&lt;/script&gt;<br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;button @click=&quot;handleClick&quot;&gt;Insert/Remove&lt;/button&gt;<br>    &lt;div v-if=&quot;show&quot; ref=&quot;content&quot;&gt;I am an content&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>const handleClick = async () =&gt; {...} has been marked as an asynchronous function.</p><p>When the <em>Insert/Remove</em> button is clicked, the value of show changes.</p><p>await nextTick() awaits until the changes reach DOM. Finally, console.log(content) logs the actual content of the reference.</p><h3>Conclusion</h3><p>If you want to catch the moment when DOM has been updated after the component’s data change, then you need to use nextTick(callback) or this.$nextTick(callback).</p><p>This function in vue.js is provide better user experience and reduces the async types of bugs from the application. Likewise in react 17 we cannot immediately uses the updated state for api call and ui changes. For that we have to add useEffect() hook with that state dependence.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51b54d60f15a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why useEffect needs functions 
too in its dependency array.]]></title>
            <link>https://medium.com/@shivanggarg48/why-useeffect-needs-functions-too-in-its-dependency-array-e031bd853159?source=rss-5660abefc278------2</link>
            <guid isPermaLink="false">https://medium.com/p/e031bd853159</guid>
            <category><![CDATA[react-js-tutorials]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-redux]]></category>
            <category><![CDATA[react-developer]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Shivanggarg]]></dc:creator>
            <pubDate>Fri, 09 Dec 2022 08:14:18 GMT</pubDate>
            <atom:updated>2023-01-04T09:33:30.914Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAMj-OH1_mW2ozStjp_DwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*xzUWp4-ZjublSpHuaL3KCg.png" /></figure><p><em>Why useEffect asks to add a function used inside its body to the array dependency<br>every single time?</em></p><p><em>The function is just called inside the body of useEffect, many times it is not the value used inside it.</em></p><p><em>The most well-known example is the Redux“dispatch” function.</em></p><p><em>But any function used in useEffect must be added to the dependency array, at<br>least if you don’t tell Eslint to not check on exhaustive depths.</em></p><p><em>The functions need to go into the array dependency simply because it is used in the useEffect callback and because of that useEffect needs to run whenever the<br>“dispatch” identity changes.</em></p><p><em>useEffect can’t know if “dispatch” in this case, returns the same API, in this case dispatching a Redux action. It sees the function as a new value every time it<br>runs. The fact “dispatch” does not change it’s just a case but useEffect can’t know<br>that.</em></p><p><em>Therefore it asks “dispatch” to be added to its dependency array!</em></p><p><em>If we have a handler, for example, created by us, useEffect asks our handler to be added into its dependency array because the hander it’s called inside useEffect<br>callback.</em></p><p><em>In that case, it’s absolutely necessary to add it to the dependency array because<br>what it returns may be different from one render to another, as long as useEffect<br>knows!</em></p><p><em>In that case, the handler identity will overwrite the returned value however and<br>determine useEffect to re-run.</em></p><p><em>That means, even though the return value might be the same as in the previous<br>render, its identity will be different!</em></p><p><em>That is a classic case when using useCallback to wrap the handler it’s<br>needed!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e031bd853159" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Never use setInterval in
useEffect hook.]]></title>
            <link>https://medium.com/@shivanggarg48/never-use-setinterval-in-useeffect-hook-cd29ee08b7be?source=rss-5660abefc278------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd29ee08b7be</guid>
            <dc:creator><![CDATA[Shivanggarg]]></dc:creator>
            <pubDate>Wed, 02 Nov 2022 17:46:48 GMT</pubDate>
            <atom:updated>2023-10-24T07:24:02.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAMj-OH1_mW2ozStjp_DwQ.png" /></figure><p><strong>setInterval</strong> and <strong>setTimeout</strong> are kinds of<br>special functions. They are JavaScript<br>interfaces to call browser APIs.</p><p>When a <strong>setInterval</strong> or a <strong>setTimeout</strong> is<br>invoked in JavaScript, it starts running<br>and will only end its cycle when the time<br>is up or when/if it is cleared out.</p><p>So, if you kick off a <strong>setInterval</strong> (or<br><strong>setTimeout</strong>) on a specific render, which means<br>when a snapshot of the state is available,<br>those 2 browser APIs functions will refer<br>to that specific snapshot of state until<br>their end.</p><p>If by chance a new render happens and a<br>new snapshot of the state is created,<br><strong>setInterval</strong> can’t pick it up as it has<br>closed over the previous snapshot of<br>state.</p><p><strong>That is a stale clouser basically.</strong></p><p>When a new <strong>setInterval</strong> is invoked again<br>on the next render, it will be totally</p><p>new compared to the previous <strong>setInterval</strong><br>(which probably didn’t get to the end<br>yet).</p><p>So, we will have a <strong>setInterval</strong> running on<br>top of another <strong>setInterval</strong>. And maybe on<br>top of a new one. Each of them has<br>access only to the state snapshot they<br>were invoked with.</p><p>How to solve this problem?</p><p>Create a custom hook and make sure to<br>pass the callback and the delay to<br>useEffect (where <strong>setInterval</strong> or<br><strong>setTimeout</strong> runs) dependencies arrays.</p><p>In this way, the useffect callback runs<br>again on delay or <strong>setInterval</strong> changing,<br>and the new <strong>setInterval</strong> (or <strong>setTimeout</strong>)<br>can pick the delay from scratch starting<br>fresh.<br>Don’t forget to clear the old one when a<br>The new set interval is kicked off.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd29ee08b7be" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>