<?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 Newton School Tech on Medium]]></title>
        <description><![CDATA[Stories by Newton School Tech on Medium]]></description>
        <link>https://medium.com/@NewtonSchoolTech?source=rss-c2b474671a1a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qmy-YX77jiwqlG46GEoLUg.png</url>
            <title>Stories by Newton School Tech on Medium</title>
            <link>https://medium.com/@NewtonSchoolTech?source=rss-c2b474671a1a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 22:13:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@NewtonSchoolTech/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[Speeding up Docker builds in CI]]></title>
            <link>https://medium.com/newton-school/speeding-up-docker-builds-in-ci-402ad0e992d6?source=rss-c2b474671a1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/402ad0e992d6</guid>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Newton School Tech]]></dc:creator>
            <pubDate>Thu, 28 Oct 2021 06:59:46 GMT</pubDate>
            <atom:updated>2021-10-28T07:14:22.738Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bwn8suk4eSpCyVjqiMIbjw.jpeg" /></figure><h3>Docker layered caching</h3><p>Docker build caches each step in the Dockerfile as an image, when it is being built. For the subsequent builds, each layer will only be re-built if that layer or any layer above it has changed since the last build. Docker build relies heavily on this caching layer, to reduce the build time.</p><p>Let’s take an example of a shortened Dockerfile here for a python service. <em>(Most actual steps are omitted here for brevity)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lMlwkOU1jrUosWMD2Jh7jA.png" /></figure><p>The very first Docker build for this can take several minutes to complete, most of the time being spend at Step 3 where the requirements are fetched and installed for the service from the requirements.txt file.</p><p>Docker caches each of these build steps as an image in its cache.</p><p>Now consider a scenario where we made some changes to the source code for the app. When another build is triggered, everything till the Step 4 can be reused from the cache as there are no changes till this step (Assuming requirements.txt was not changed).</p><p>A new build now will be faster than the first build, because the dependencies need not be downloaded again. The image layer that has all the dependencies downloaded (Step 4) will be used from cache. Steps 5, 6 and 7 are run on top of this layer, and would not take more than a couple of seconds to complete. This brings down the build time from several minutes to a couple of seconds for our subsequent builds.</p><blockquote><em>The heavier and less prone to change steps, like installing dependencies should be done earlier in the build phase. Thus the subsequent builds can make use of caching, and not rerunning the costly steps again, to reap the full benefits from this docker layered caching mechanism.</em></blockquote><h3>CI Environment : AWS Codebuild</h3><p>Let’s take AWS Codebuild as a CI environment for this discussion.</p><p>Whenever a build is triggered via Codebuild, it acquires a fresh on-demand EC2 instances to run the build process. Once the build is completed, and if another build is not triggered within 15 minutes, Codebuild terminates this newly acquired EC2 instance.</p><p>Due to the build being run in a fresh instance each time with Codebuild, we lose the local docker caching layer for subsequent builds. This increases the build time by orders of magnitude.</p><h3>Docker in-line cache</h3><p>In addition to local build cache, the docker builder can reuse the cache generated from previous builds with the --cache-from flag pointing to an image in the registry.</p><p>To use an image as a cache source, cache metadata needs to be written into the image on creation. This can be done by setting --build-arg BUILDKIT_INLINE_CACHE=1 when building the image. After that, the built image can be used as a cache source for subsequent builds.</p><p>The following example builds an image with inline-cache metadata and pushes it to a registry :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bd2nDSV25F7vslW37o2_iw.png" /></figure><p>After pushing the image, the image can be used as cache source on another machine. The cache metadata enables using the image as a cache source for another build</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P6P-vxu-M25VcaY8v8FmoA.png" /></figure><h3>Multi-stage Docker build</h3><p>With the multi-stage builds, the intermediate stage images are discarded before the final image is created. Due to this, they can’t be used directly as inline cache for subsequent builds.</p><p>To overcome this, we need to build and push each stage of the build, and then use the images of each stage as the in-line cache for subsequent builds. The --target option can be used to build each stage of the multi-stage build separately.</p><p>Let’s take the same example of a shortened multi-stage Dockerfile here for a python service. <em>(Most actual steps are omitted here for brevity)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJrx2vzh4WKYTWOABYzrzA.png" /></figure><p>We can build the builder stage separately and push it to repo using the following command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uQblMbhKszDf3Eiu6WIcBg.png" /></figure><p>Now final build can be done using the builder cache as an in-line cache using the following command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FmOkzbfvfBuAZmUGWzstXg.png" /></figure><p>The final code for using docker inline cache with a multi-stage build in Codebuild, using ECR as the container registry, is added below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*5mscaJ8cO36Rw92kigCn_Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=402ad0e992d6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newton-school/speeding-up-docker-builds-in-ci-402ad0e992d6">Speeding up Docker builds in CI</a> was originally published in <a href="https://medium.com/newton-school">Newton School</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does useEffect() work?]]></title>
            <link>https://medium.com/newton-school/how-does-useeffect-work-c29982ef4c4a?source=rss-c2b474671a1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c29982ef4c4a</guid>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[usestate]]></category>
            <dc:creator><![CDATA[Newton School Tech]]></dc:creator>
            <pubDate>Tue, 12 Oct 2021 14:22:20 GMT</pubDate>
            <atom:updated>2021-10-12T14:22:20.763Z</atom:updated>
            <content:encoded><![CDATA[<p>useEffect hook is the solution to many problems: how to fetch data when a component mounts, how to run code when state changes or when a prop changes, how to set up timers or intervals, you name it.</p><p>All this power comes with a tradeoff: useEffect can be confusing until you understand how it works.</p><p>There are tons of posts/articles explaining the concept. In this post, we are going to learn the working of useEffect in the simplest terms and with examples (Nothing different from what we have been teaching students at Newton School)</p><h3>useEffect() is for side-effects</h3><p>A functional React component uses props and/or state to calculate the output. If the functional component makes calculations that don’t target the output value, then these calculations are named side-effects.</p><p>Examples of side-effects are fetch requests, manipulating DOM directly, using timer functions like setTimeout(), and more.</p><h3>The working of useEffect</h3><p>Let’s start with an example</p><pre>const Counter = () =&gt; {<br>  const [count, setCount] = useState(0);<br><br>  useEffect(() =&gt; {<br>    let timerId;<br><br>    console.log(&quot;useEffect as mount&quot;);<br><br>    const callback = () =&gt; {<br>      setCount((c) =&gt; c + 1);<br>    };<br><br>    timerId = setInterval(callback, 1000);<br><br>    return () =&gt; {<br>      console.log(&quot;useEffect as unmount&quot;);<br>      clearInterval(timerId, callback);<br>    };<br>  });<br><br>  return &lt;h1&gt;{count}&lt;/h1&gt;;<br>};</pre><p>This code basically increases the count after each second and updates the DOM according to the current value of count.</p><p>Now, take some time and think what would be printed in console for this piece of code?<br>. . . . .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nps-lawHVAli3rg0YNG15g.png" /></figure><p>Surprising? Not if you completely understand how useEffect works.</p><h3>Let’s Dive Deeper</h3><p>Let us understand how useEffect works under the hood. We are going to divide the explanation of working into two parts</p><ol><li>Rendering</li><li>Re-rendering</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mc3MMv04fUplw92BaJ82aQ.png" /></figure><h3>The Rendering Phase</h3><ol><li>JSX is rendered.</li><li>Body of useEffect is executed.</li><li>cleanup function is stored in memory.</li></ol><h3>The Re-rendering Phase</h3><ol><li>JSX is rendered.</li><li>Stored cleanup function (if any) is executed.</li><li>Body of useEffect is executed.</li><li>cleanup function is stored in memory.</li></ol><p>Interesting. Let’s now decode the Counter example used to demonstrate the hook.</p><h3>What happens in the rendering phase?</h3><p>During the render phase, counter starts with a value 0. Now an interval is set which increments the counter each second. It also prints useEffect as mount in the console. Finally, interval clearance function (acting as cleanup function here) is stored in memory.</p><h3>What happens when it re-renders?</h3><p>As soon as count variable is updated, useEffect executes again. Why?</p><p>This is because we have not passed the dependency array. In this case, useEffect runs on every re-render.</p><p>During the re-rendering phase, updated counter value is rendered in DOM. As per the execution steps, stored cleanup function now needs to be executed. That is, clearInterval function will be invoked and it will clear out the timer that started in the previous cycle. The execution continues and a new interval is set and clearance function is stored once again in the memory.</p><p>Pheww!! It’s a lot to digest. One might think that a continuous timer is updating the count variable each second but when decoded it is inferred that it&#39;s a new timer which is started after each render in order to increment the counter.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fobjective-rubin-l0swd%3Ffile%3D%2Fsrc%2FCounter.js%3A448-449&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fobjective-rubin-l0swd%3Ffile%3D%2Fsrc%2FCounter.js%3A448-449&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fl0swd%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/2014da9e68ea5bc2970522992baf874b/href">https://medium.com/media/2014da9e68ea5bc2970522992baf874b/href</a></iframe><h3>Run useEffect() only once</h3><p>There might be times where you want to run the effect only once. To achieve the same, we need to tell React that when should it fire the effect. We can do it using the **dependency array**.</p><p>The dependency array in useEffect lets you specify the conditions to trigger it. If you provide useEffect an empty dependency array, it’ll run exactly once, as in this example</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fl0swd&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fl0swd&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fl0swd%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/344bb7b258b9d6678f42e03fd798d7ed/href">https://medium.com/media/344bb7b258b9d6678f42e03fd798d7ed/href</a></iframe><p>Adding variables to the dependency array tells useEffect: “Hey, I need you to run only if this value changes”. Interestingly, you can pass any kind of variable as a dependency in the dependency list.</p><p>It now becomes significantly easy to understand why does empty dependency array corresponds to <strong>componentDidMount</strong> in class components.</p><h3>Food for thought</h3><p>Using all the facts stated in the post, one might be able to deduce why cleanup function acts same as componentWillUnmount</p><pre>const Counter = () =&gt; {</pre><pre>  const [count, setCount] = useState(0);</pre><pre>  useEffect(() =&gt; {</pre><pre>     let timerId;</pre><pre>     console.log(&quot;useEffect as mount&quot;);</pre><pre>     const callback = () =&gt; {</pre><pre>     setCount((c) =&gt; c + 1);<br>     };</pre><pre>     timerId = setInterval(callback, 1000);</pre><pre>     return function cleanup() {</pre><pre>       console.log(&quot;useEffect as unmount&quot;);</pre><pre>       clearInterval(timerId, callback);</pre><pre>     };</pre><pre>  });</pre><pre>  return &lt;h1&gt;{count}&lt;/h1&gt;;</pre><pre>};</pre><h3>Conclusion</h3><p>In our opinion, understanding the underlying design concepts and best practices of the useEffect hook is a key skill to master if you wish to become a proficient React developer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c29982ef4c4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newton-school/how-does-useeffect-work-c29982ef4c4a">How does useEffect() work?</a> was originally published in <a href="https://medium.com/newton-school">Newton School</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Product Tours for your React App]]></title>
            <link>https://medium.com/newton-school/build-product-tours-for-your-react-app-b004df414cc0?source=rss-c2b474671a1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b004df414cc0</guid>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Newton School Tech]]></dc:creator>
            <pubDate>Thu, 09 Sep 2021 11:28:23 GMT</pubDate>
            <atom:updated>2021-09-09T11:28:23.801Z</atom:updated>
            <content:encoded><![CDATA[<h3>Quick Summary:</h3><p><em>Showcasing new product features to users can get tedious. In this article, you’ll learn how to onboard users into a new UX and how to familiarize them with UI functionality while keeping them engaged.</em></p><h3>Introduction:</h3><p>Product tours are powerful tools to introduce users to a new product and to help them find their bearings. Product tours can be used to showcase high-value features that are being underused.</p><p>In this article, you’ll learn about building product tours in React App.</p><p>There exist many libraries for implementing tours in your React app. We are going to stick to <a href="https://www.npmjs.com/package/react-joyride">React Joyride</a>.</p><h3>Why React Joyride? You might ask.</h3><p>Product tours, especially for really big web apps, require customization, and that sets React Joyride apart from other libraries.</p><h3>Building A Simple Product Tour</h3><p>We’ll be covering the following steps:</p><ul><li>Define tour steps</li><li>Enable Action buttons in each step</li><li>Customize styles</li><li>Auto Start the tour</li><li>Start tour manually</li><li>Handling state switch</li></ul><h3>Define Steps for the Tour</h3><p>To begin with, ensure that you’re targeting the particular elements that will hold the content of the tour on the page. You can do this by specifying the query selector like we have done below:</p><pre>import React from &quot;react&quot;;<br>import JoyRide from &quot;react-joyride&quot;;<br>const TOUR_STEPS = [<br>        {<br>          content: &lt;h2&gt;Let&#39;s begin our journey!&lt;/h2&gt;,<br>          placement: &#39;center&#39;,<br>          target: &#39;body&#39;,<br>        },<br><br>        {<br>          content: &#39;These are our super awesome projects!&#39;,<br>          placement: &#39;bottom&#39;,<br>          styles: {<br>            options: {<br>              width: 300,<br>            },<br>          },<br>          target: &#39;.demo__projects h2&#39;,<br>          title: &#39;Our projects&#39;,<br>        }<br>      ]</pre><h3>Enable Actions In Each Step</h3><p><strong>Next, Back Button</strong></p><p>To display these buttons, send continuous={true}</p><pre>const Tour = () =&gt; {<br>  return (<br>    &lt;&gt;<br>      &lt;JoyRide steps={TOUR_STEPS} continuous={true} /&gt;<br>    &lt;/&gt;<br>  );<br>};</pre><p><strong>Skip Button</strong></p><pre>const Tour = () =&gt; {<br>  return (<br>    &lt;&gt;<br>      &lt;JoyRide steps={TOUR_STEPS} continuous={true} showSkipButton={true} /&gt;<br>    &lt;/&gt;<br>  );<br>};</pre><h3>Customize Styles</h3><pre>const Tour = () =&gt; {<br>  return (<br>    &lt;&gt;<br>      &lt;JoyRide<br>        steps={TOUR_STEPS}<br>        continuous={true}<br>        showSkipButton={true}<br>        styles={{<br>          buttonNext: {<br>            // Styles for Next button<br>          },<br>          buttonBack: {<br>          //Styles for Back Button<br>          }<br>        }}<br>      /&gt;<br>    &lt;/&gt;<br>  );<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyhf0CKK2DDkUopcAo_jjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YF2Vg6IBX7HeBRQyU8hRTA.png" /></figure><h3>Auto-start the Tour</h3><p>If you are using v1, an autostart prop will fulfill the purpose.</p><p>However, this prop was deprecated in subsequent versions. From v2 onwards you need to add disableBeacon: true to the first step of the TOUR_STEPS array and it will autoStart the tour.</p><h3>Manually Starting the Tour</h3><p>In order to trigger the tour manually, we need to keep track of user intentions. We need to keep the state to know if the tour has been triggered manually</p><pre>const [isRunning, setIsRunning] = useState(false);<br><br><br>&lt;Joyride run={isRunning} {...remainingProps}/&gt;</pre><p>There can be various cases of the tour that you might need to manage. Refer to <a href="https://codesandbox.io/s/5x6m6o98vp">this example</a> to manage tours manually.</p><h3>Handling State</h3><p>There might be instances where you may want to change the state and then mount the step. For Example, You have a sidebar that is initially collapsed. You want to show functionality from the sidebar. To achieve that, you must guide the user to open the sidebar and then focus on the required element.</p><p>To achieve that using Joyride, you can define the steps as follows:</p><pre>const TOUR_STEPS=[<br>          {<br>            content: (<br>              &lt;div&gt;<br>                You can interact with your own components through the spotlight.<br>                &lt;br /&gt;<br>                Click the menu above!<br>              &lt;/div&gt;<br>            ),<br>            disableBeacon: true,<br>            disableOverlayClose: true,<br>            hideCloseButton: true,<br>            hideFooter: true,<br>            placement: &#39;bottom&#39;,<br>            spotlightClicks: true,<br>            styles: {<br>              options: {<br>                zIndex: 10000,<br>              },<br>            },<br>            target: this.menu!,<br>            title: &#39;Menu&#39;,<br>          },<br>          {<br>            content: &#39;This is our sidebar, you can find everything you need here&#39;,<br>            placement: &#39;right&#39;,<br>            spotlightPadding: 0,<br>            styles: {<br>              options: {<br>                zIndex: 10000,<br>              },<br>            },<br>            target: this.sidebar!,<br>            title: &#39;Sidebar&#39;,<br>          },<br>          {<br>            content: &#39;Check the availability of the team!&#39;,<br>            placement: &#39;bottom&#39;,<br>            styles: {<br>              options: {<br>                zIndex: 10000,<br>              },<br>            },<br>            target: this.calendar!,<br>            title: &#39;The schedule&#39;,<br>          },</pre><p>This will guide the user to click on the spotlight element. Hence, continuing the tour efficiently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2Vix2VvqjE3gwLJJBhDng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9e9pnO8WSvxqqvWNP3SKlQ.png" /></figure><h3>Conclusion</h3><p>We’ve seen how to build a product tour in a web UI with React.</p><p>Now, you can experiment with the React Joyride library and come up with something awesome in your next web app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b004df414cc0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newton-school/build-product-tours-for-your-react-app-b004df414cc0">Build Product Tours for your React App</a> was originally published in <a href="https://medium.com/newton-school">Newton School</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>