<?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 Alexandru Cambose on Medium]]></title>
        <description><![CDATA[Stories by Alexandru Cambose on Medium]]></description>
        <link>https://medium.com/@alexcambose?source=rss-75b8551cab97------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MFqgs8IhpMTUjzDaGguCBA.png</url>
            <title>Stories by Alexandru Cambose on Medium</title>
            <link>https://medium.com/@alexcambose?source=rss-75b8551cab97------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:12:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexcambose/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[Why are junior developers essential in a team?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/why-are-junior-developers-essential-in-a-team-5442e4623051?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/2600/1*zGi3aWhTMaUvuAH3-M1U1Q.jpeg" width="5184"></a></p><p class="medium-feed-snippet">Unlocking the reasons behind choosing a mixed Seniority Team: Benefits for Your Project and Aspiring Juniors</p><p class="medium-feed-link"><a href="https://medium.com/swlh/why-are-junior-developers-essential-in-a-team-5442e4623051?source=rss-75b8551cab97------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/why-are-junior-developers-essential-in-a-team-5442e4623051?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/5442e4623051</guid>
            <category><![CDATA[recruiting]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[junior]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[hiring]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Thu, 08 Jun 2023 14:06:00 GMT</pubDate>
            <atom:updated>2023-06-08T14:06:00.209Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Sentry tracing decorator in Typescript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/sentry-tracing-decorator-in-typescript-6d9607858ece?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/1800/1*jT1pyv-UqFfT72Pne4VzvA.png" width="1800"></a></p><p class="medium-feed-snippet">Enhancing Debugging and Error Tracking with the Power of a Sentry Tracing Decorator in Typescript.</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/sentry-tracing-decorator-in-typescript-6d9607858ece?source=rss-75b8551cab97------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/sentry-tracing-decorator-in-typescript-6d9607858ece?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d9607858ece</guid>
            <category><![CDATA[sentry]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Tue, 30 May 2023 13:33:41 GMT</pubDate>
            <atom:updated>2023-05-31T04:38:05.087Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Escape the Try-Catch Hell]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/escaping-the-try-catch-hell-176884be4ff2?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/1640/1*-W46lA4_hO9T2aK8EhFcLQ.png" width="1640"></a></p><p class="medium-feed-snippet">Promises fix the callback hell, async/await fixes the Promise hell, but there&#x2019;s one more thing&#x2026;</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/escaping-the-try-catch-hell-176884be4ff2?source=rss-75b8551cab97------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/escaping-the-try-catch-hell-176884be4ff2?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/176884be4ff2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Wed, 28 Jul 2021 07:37:32 GMT</pubDate>
            <atom:updated>2021-07-28T07:37:32.615Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Benchmark Javascript easily]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@alexcambose/benchmark-javascript-easily-6fdb8d541648?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/1000/1*VSh1uxhKoox55G9ubcsUpg.png" width="1000"></a></p><p class="medium-feed-snippet">How to use vanilla js to benchmark heavy computations</p><p class="medium-feed-link"><a href="https://medium.com/@alexcambose/benchmark-javascript-easily-6fdb8d541648?source=rss-75b8551cab97------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@alexcambose/benchmark-javascript-easily-6fdb8d541648?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fdb8d541648</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[computing]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[benchmark]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 13:32:43 GMT</pubDate>
            <atom:updated>2020-06-08T13:42:47.806Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How JWT works? The implementation]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/how-jwt-works-in-depth-354cb5dc360d?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/1000/1*IALQqvNTXxexyUW0HB4fwA.png" width="1000"></a></p><p class="medium-feed-snippet">Understanding and building a simple JWT library from scratch.</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/how-jwt-works-in-depth-354cb5dc360d?source=rss-75b8551cab97------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/how-jwt-works-in-depth-354cb5dc360d?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/354cb5dc360d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[json-web-token]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Thu, 04 Jun 2020 21:16:47 GMT</pubDate>
            <atom:updated>2020-06-25T19:38:51.935Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How JWT works — in depth]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/how-jwt-works-in-depth-604c93ec20a4?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/1000/1*bZ7pCr_PJuL4XiX7lo8-pw.png" width="1000"></a></p><p class="medium-feed-snippet">Why and how it works? Understanding and building a simple JWT library from scratch. (part 1)</p><p class="medium-feed-link"><a href="https://medium.com/swlh/how-jwt-works-in-depth-604c93ec20a4?source=rss-75b8551cab97------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/how-jwt-works-in-depth-604c93ec20a4?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/604c93ec20a4</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[json-web-token]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[jwt]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Thu, 04 Jun 2020 21:15:36 GMT</pubDate>
            <atom:updated>2020-07-03T12:03:23.855Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Provably fair system in javascript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@alexcambose/provably-fair-system-in-javascript-6457e028d2aa?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/820/1*xuvd2BQe6xYjU9Yc9iCnkg.png" width="820"></a></p><p class="medium-feed-snippet">What is and how to build a provably fair system in javascript</p><p class="medium-feed-link"><a href="https://medium.com/@alexcambose/provably-fair-system-in-javascript-6457e028d2aa?source=rss-75b8551cab97------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@alexcambose/provably-fair-system-in-javascript-6457e028d2aa?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/6457e028d2aa</guid>
            <category><![CDATA[gambling]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[dice]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Sat, 12 Oct 2019 21:38:12 GMT</pubDate>
            <atom:updated>2020-06-06T16:41:18.247Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Creating a parallax effect with Motus]]></title>
            <link>https://medium.com/@alexcambose/creating-a-parallax-effect-with-motus-af89bdc3ce1a?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/af89bdc3ce1a</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[parallax]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 20:40:01 GMT</pubDate>
            <atom:updated>2019-04-14T11:51:50.115Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*00dxSznXefp7o_HuQB7N2w.png" /></figure><p>How to easily create a parallax effect with <a href="https://github.com/alexcambose/motus">Motus</a> scroll animation library</p><p>Prerequisites:</p><ul><li>a browser</li><li>minimal javascript, nodejs and CSS knowledge</li><li>nodejs installed</li></ul><p>Final result</p><p><a href="https://alexcambose.ro/motus/parallax-demo">https://alexcambose.ro/motus/parallax-demo</a></p><h3>Initialization</h3><p>In this article, I will use Parcel for bundling javascript and CSS because it’s fast and doesn’t require any additional setup.</p><pre>npm i parcel motus -S</pre><p>Let’s add a simple script to our package.json file</p><pre>...<br>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;parcel serve index.html&quot;,<br>}<br>...</pre><p>and create 3 files: <strong>index.html</strong>, <strong>script.js</strong>, and <strong>style.scss</strong>.</p><h3><strong>Website layout</strong></h3><p>First of all, we need to define the HTML structure where our website will live.</p><blockquote><strong>index.html</strong></blockquote><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=<strong>&quot;en&quot;</strong>&gt;<br>&lt;head&gt;<br>    &lt;meta charset=<strong>&quot;UTF-8&quot;</strong>&gt;<br>    &lt;title&gt;<strong>Motus Demo</strong>&lt;/title&gt;<br>    &lt;meta name=<strong>&quot;viewport&quot; </strong>content=<strong>&quot;width=device-width, initial-scale=1.0&quot;</strong>&gt;<br>    &lt;link href=<strong>&quot;https://fonts.googleapis.com/css?family=Oxygen+Mono&quot; </strong>rel=<strong>&quot;stylesheet&quot;</strong>&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;header&gt;<br>        &lt;img src=<strong>&quot;https://i.imgur.com/9I7KKgx.png&quot; </strong>class=<strong>&quot;flower&quot; </strong>alt=<strong>&quot;flower&quot;</strong>/&gt;<br>        &lt;h1&gt;<strong>Welcome</strong>&lt;/h1&gt;<br>    &lt;/header&gt;<br>    &lt;section&gt;<br>        &lt;p&gt;<strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid, amet animi corporis deserunt eius esse ex id inventore iste magnam minima molestias necessitatibus nisi nulla pariatur, quo, sunt ut! Quidem?</strong>&lt;/p&gt;<br>    &lt;/section&gt;<br>    &lt;section&gt;<br>        &lt;h1&gt;<strong>This is a heading</strong>&lt;/h1&gt;<br>    &lt;/section&gt;<br>    &lt;section&gt;<br>        &lt;p&gt;<strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid, amet animi corporis deserunt eius esse ex id inventore iste magnam minima molestias necessitatibus nisi nulla pariatur, quo, sunt ut! Quidem?</strong>&lt;/p&gt;<br>    &lt;/section&gt;<br>    &lt;footer&gt;&lt;p&gt;<strong>Build with </strong>&lt;a target=<strong>&quot;_blank&quot; </strong>href=<strong>&quot;https://github.com/alexcambose/motus&quot;</strong>&gt;<strong>Motus</strong>&lt;/a&gt;&lt;/p&gt;&lt;/footer&gt;<br>    &lt;script src=<strong>&quot;index.js&quot;</strong>&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>also, note the <em>script</em> import at the bottom of the <em>body</em> tag.</p><p>Let’s also add a little bit of styling in style.scss file</p><blockquote>style.scss</blockquote><pre>body {<br>  <em>font-family</em>: &#39;Oxygen Mono&#39;, <strong>monospace</strong>;<br>  <em>margin</em>: 0;<br>}<br><br>header {<br>  <em>background</em>: url(https://medium.com/%3Cem%3Ehttps://i.imgur.com/AzqJ7WR.jpg%3C/em%3E);<br>  <em>background-position</em>: <strong>center</strong>;<br>  <em>background-size</em>: <strong>cover</strong>;<br>  <em>height</em>: 50<strong>vh</strong>;<br>  <em>display</em>: <strong>flex</strong>;<br>  <em>justify-content</em>: <strong>center</strong>;<br>  <em>align-items</em>: <strong>center</strong>;<br>  <em>position</em>: <strong>relative</strong>;<br>  <em>font-size</em>: 2<strong>em</strong>;<br>  <em>letter-spacing</em>: 2<strong>px</strong>;<br>}<br><br>.flower {<br>  <em>width</em>: 20<strong>vw</strong>;<br>  <em>position</em>: <strong>absolute</strong>;<br>  <em>top</em>: 50%;<br>  <em>left</em>: 20%;<br>  <em>transform</em>: translate(-50%, -50%);<br>}<br><br>section {<br>  @extend header;<br>  <em>padding</em>: 30<strong>px </strong>10<strong>vw</strong>;<br>  <em>background</em>: #333;<br>  <em>color</em>: #fff;<br>  <em>font-size</em>: 1.3<strong>em</strong>;<br>  <em>line-height</em>: 40<strong>px</strong>;<br>  &amp;:nth-of-type(2) {<br>    @extend header;<br>    <em>background-image</em>: url(https://medium.com/%3Cem%3Ehttps://i.imgur.com/prxIGf5.jpg%3C/em%3E);<br>    <em>filter</em>: grayscale(70%);<br>  }<br>  &amp;:nth-of-type(3) {<br>    <em>background-color</em>: #FAFAFA;<br>    <em>color</em>: #555;<br>  }<br>}<br><br>footer {<br>  @extend section;<br>  <em>height</em>: 20<strong>vh</strong>;<br>}<br>a {<br>  <em>text-decoration</em>: <strong>none</strong>;<br>  <em>color</em>: #fe001a;<br>}</pre><p>Note that we didn’t include the style file directly into the HTML file, we will include it via the script.js file so that parcel can compile it into a valid CSS.</p><blockquote>script.js</blockquote><pre>import &#39;./styles.scss&#39;;</pre><p>If everything went right you should have a nice looking page like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*krAwAAI5iMjOw58graAYaQ.png" /><figcaption>Don’t forget to execute `npm start` to open the parcel development server</figcaption></figure><h3>Creating animations</h3><p>Firstly we need to import motus:</p><blockquote>script.js</blockquote><pre>import &#39;./styles.scss&#39;;<br>import Motus from &#39;motus&#39;;</pre><p>next, let’s define the parallax animation for the <em>header</em>:</p><pre>import &#39;./styles.scss&#39;;<br>import Motus from &#39;motus&#39;;</pre><pre>const headerAnimation = new Motus.Animation({<br>    $el: <em>document</em>.querySelector(&#39;header&#39;),<br>    keyframes: [<br>        {backgroundPositionY: 10}<br>    ],<br>});<br>Motus.addAnimation(headerAnimation);</pre><ul><li>$elparameter points to the dom element that needs to have the animation applied</li><li>keyframes are the rules that the animation needs to follow, in this case, backgroundPositionY starts at 0 when the scrollY is at 0 and goes to 10 when the scrollY position reaches the height of the element</li></ul><p>We can also add more animations</p><pre>...<br>const flowerAnimation = new Motus.Animation({<br>    $el: <em>document</em>.querySelector(&#39;header &gt; img&#39;),<br>    startPoint: 0,<br>    endPoint: 500,<br>    keyframes: [<br>        {marginTop: 170}<br>    ],<br>});<br>Motus.addAnimation(flowerAnimation);<br><br>const sectionAnimation = new Motus.Animation({<br>    $el: <em>document</em>.querySelector(&#39;section:nth-child(3)&#39;),<br>    keyframes: [<br>        {backgroundPositionY: 10}<br>    ],<br>});<br>Motus.addAnimation(sectionAnimation);</pre><p>And the final result should look similar to this:</p><p><a href="https://alexcambose.ro/motus/parallax-demo">Motus Demo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af89bdc3ce1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS offsetTop property is not great and here is why]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@alexcambose/js-offsettop-property-is-not-great-and-here-is-why-b79842ef7582?source=rss-75b8551cab97------2"><img src="https://cdn-images-1.medium.com/max/2600/1*_ruNu9jYD7qzikQg5bB15Q.png" width="3000"></a></p><p class="medium-feed-snippet">offsetTop and offsetLeft is not what you may think</p><p class="medium-feed-link"><a href="https://medium.com/@alexcambose/js-offsettop-property-is-not-great-and-here-is-why-b79842ef7582?source=rss-75b8551cab97------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@alexcambose/js-offsettop-property-is-not-great-and-here-is-why-b79842ef7582?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/b79842ef7582</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Thu, 07 Feb 2019 09:46:12 GMT</pubDate>
            <atom:updated>2019-02-07T11:20:53.119Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[React Hooks in 3 minutes]]></title>
            <link>https://medium.com/@alexcambose/tldr-of-react-hooks-a994d0d44883?source=rss-75b8551cab97------2</link>
            <guid isPermaLink="false">https://medium.com/p/a994d0d44883</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alexandru Cambose]]></dc:creator>
            <pubDate>Sat, 03 Nov 2018 22:59:28 GMT</pubDate>
            <atom:updated>2018-11-06T14:08:49.864Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irVQowoE01OYqAsuGzHycg.png" /><figcaption><a href="https://reactjs.org/docs/hooks-state.html">https://reactjs.org/docs/hooks-state.html</a></figcaption></figure><p>Hooks are a new feature of React that has just been introduced in version 16.7.0^<em> </em>and provides us with an awesome way to <strong>declare state and side effects without using a class.</strong></p><p>What we will be covering here</p><ul><li><strong>State Hook</strong></li><li><strong>Effect Hook</strong></li></ul><p>Let’s start with a typical example of a class component that you can find anywhere:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZTttR471jdRvRSCajFzXg.png" /><figcaption>Displays an input which acts as a search box for searching users from an API (live demo: <a href="https://codesandbox.io/s/j363v61pm3">https://codesandbox.io/s/j363v61pm3</a>)</figcaption></figure><p>We will use this example as a starting point to learn the state and effect hooks by converting it into a functional component.</p><h3>The state hook:</h3><p>The useState hook is the new way of creating a local state in a functional component that is preserved between calls. It takes as argument the initial value of the state and returns a pair of values: the current state and a function that updates it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*43N7Pl_oz70IGjUP5i4iHw.png" /><figcaption><a href="https://codesandbox.io/s/k0003n2pj5">https://codesandbox.io/s/k0003n2pj5</a></figcaption></figure><p>What we did here:</p><ul><li>We import <strong>useState</strong> from <strong>react</strong></li><li>We called useState hook to declare a new state</li><li>We unpacked the returned array into two different variables using the <strong>destructuring assignment</strong> syntax</li><li>When the user types something in the input we update the state by calling the corresponding function, in our expample setSearch</li></ul><p>Let’s also define a new state variable that will hold the array of users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F-7jy587RheRIRUW4I7VaQ.png" /><figcaption><a href="https://codesandbox.io/s/912o4wr6po">htps://codesandbox.io/s/912o4wr6po</a></figcaption></figure><h3>The Effect hook:</h3><p>The useEffect hook is used for side effects in React function components. By default, it runs both after the first render <em>and</em> after every DOM update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckCEh5WxMD5ZrvZ7ASQ84A.png" /><figcaption><a href="https://codesandbox.io/s/ko27q4knzv">https://codesandbox.io/s/ko27q4knzv</a> Wrong! It will call the effect each time users array changes because the DOM changes.</figcaption></figure><p>Although the above code works fine it contains a bug. The effect runs each time the DOM changes and the DOM changes each time users array is updated and the users array is updated each time the effect changes…∞ (you got the ideea)</p><p>This is where the second argument comes into play.</p><p>If we pass [users]as the second argument, react will compare the value of users from the <strong>current render</strong> with the one from the <strong>previous render</strong> and will <strong>skip the effect if the value is not changed</strong>. If there are multiple items in the array, React will re-run the effect even if just one of them is different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aWBCDJjWwPJP1fnopfSj-A.png" /><figcaption><a href="https://codesandbox.io/s/3j3mjoy95">https://codesandbox.io/s/3j3mjoy95</a></figcaption></figure><blockquote>If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array ([]) as a second argument.</blockquote><p>To run something before a component unmounts, we just have to <strong>return a function:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AkrHg7Mvfb5I9FOCFlj9Cw.png" /><figcaption>In order to get always the latest state you can pass a function for the state update function</figcaption></figure><p>And that’s pretty much it.</p><h4>Rules of hooks</h4><ul><li>only call hooks at the top level of your function, <strong>not in loops, conditionals, or nested functions. </strong>React needs to keep track of the order in which hooks are called so that it will correctly preserve the state of Hooks between multiple calls</li><li>only call hooks from React function components</li><li>hook names should start with <strong>“use” </strong>followed by the hook name (something like: /<strong><em>use</em></strong><em>[0–9a-zA-Z]+/)</em></li></ul><p>Note that if you want to play around with the new React hook API you will also need ”react-dom”: “16.7.0-alpha.0”</p><h4>Have fun ! 😄</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a994d0d44883" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>