<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: GermaVinsmoke</title>
    <description>The latest articles on Forem by GermaVinsmoke (@germavinsmoke).</description>
    <link>https://forem.com/germavinsmoke</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F390272%2Fdaadf14d-faea-41de-8716-a741565c5ae0.png</url>
      <title>Forem: GermaVinsmoke</title>
      <link>https://forem.com/germavinsmoke</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/germavinsmoke"/>
    <language>en</language>
    <item>
      <title>How to Create a Random Hex Colour Generator in React</title>
      <dc:creator>GermaVinsmoke</dc:creator>
      <pubDate>Thu, 16 Sep 2021 09:19:23 +0000</pubDate>
      <link>https://forem.com/germavinsmoke/how-to-create-a-random-hex-colour-generator-in-react-2fp6</link>
      <guid>https://forem.com/germavinsmoke/how-to-create-a-random-hex-colour-generator-in-react-2fp6</guid>
      <description>&lt;p&gt;If you’re looking for the source code, then it’s available in the video.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/PPZQ4-oPnAw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this, we’re going to see how to create a full-screen hex colour generator that generates colours randomly.&lt;/p&gt;

&lt;p&gt;We’ll create a separate component for generating this colour, and name it &lt;strong&gt;RandomColor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J_PLdWYF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9l0mizxqikcyxvfr1c1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J_PLdWYF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9l0mizxqikcyxvfr1c1.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  useState
&lt;/h3&gt;

&lt;p&gt;It is used to store the generated colour and also to update the colour on a button click. It’ll help us in updating the colour of the page reactively. 😏&lt;/p&gt;

&lt;h3&gt;
  
  
  getRgb
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This function is used to get a random value. The range of this function is 0 to 255 (because RGB ranges from 0 to 255 🧐).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Math.random&lt;/code&gt; generates a floating-point value between 0 and 1. On multiplying with &lt;strong&gt;n&lt;/strong&gt;, we will get the value in the range of &lt;strong&gt;0 and n — 1&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;But it’ll still be in decimal, so we can use Math.floorto get the floor round-off value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  rgbToHex
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This function is used to generate the hex code of the colour based on the three values of &lt;strong&gt;red&lt;/strong&gt;, &lt;strong&gt;blue&lt;/strong&gt;, and &lt;strong&gt;green&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;We are mapping over these 3 values and applying &lt;code&gt;toString()&lt;/code&gt; function over the value. We can provide a &lt;strong&gt;radix&lt;/strong&gt; argument to this function which converts the number as per the base value provided. - Here, we are using &lt;strong&gt;16&lt;/strong&gt; which is for &lt;strong&gt;hexadecimal numbers&lt;/strong&gt; because hex code colour is made up of &lt;strong&gt;hexadecimal numbers&lt;/strong&gt; 🧐.
Then we are checking whether the length of the result is 1 or more, if it’s 1 then we’re adding &lt;strong&gt;0&lt;/strong&gt; in front of it to normalize it.&lt;/li&gt;
&lt;li&gt;At last, we’re joining the array and adding a &lt;code&gt;#&lt;/code&gt; in front of the generated string.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  handleGenerate
&lt;/h3&gt;

&lt;p&gt;This function is called whenever we click on the button. It creates a colour object and then passes those red, blue, and green values to &lt;strong&gt;rgbToHex&lt;/strong&gt; function. The returned value is used to update the colour.&lt;/p&gt;

&lt;p&gt;At last, we are setting the colour to the &lt;code&gt;backgroundColor&lt;/code&gt; of the &lt;strong&gt;container&lt;/strong&gt; and text &lt;code&gt;color&lt;/code&gt; of the &lt;strong&gt;button&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uP6T_Yh8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m57paawm3bmwajnnlw56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uP6T_Yh8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m57paawm3bmwajnnlw56.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The styling part of the application is done like this.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;container&lt;/strong&gt; class is just to make sure the whole screen area is used and the button is placed in the centre. transition is just to provide a smooth &lt;strong&gt;transition&lt;/strong&gt; of colour whenever a new colour is generated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Button&lt;/strong&gt; styling in order to make it look good. &lt;strong&gt;transform&lt;/strong&gt; and &lt;strong&gt;box-shadow&lt;/strong&gt; are used to provide a 3D effect to the button whenever we hover on the button.&lt;/p&gt;

&lt;p&gt;And by doing all this we’ll finally have our random full-screen colour generator complete. It’ll look something like this 🤩👇🏻&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TQSpViS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhb4fw7v0fayqnxbo1nd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TQSpViS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhb4fw7v0fayqnxbo1nd.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it, this is where our journey ends. I hope you were able to reach this point. 😃&lt;/p&gt;

&lt;p&gt;Thanks!  &lt;/p&gt;

</description>
      <category>react</category>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to create a custom cursor in React Part — 2 [Mathematical explanation]</title>
      <dc:creator>GermaVinsmoke</dc:creator>
      <pubDate>Sat, 19 Jun 2021 13:53:37 +0000</pubDate>
      <link>https://forem.com/germavinsmoke/how-to-create-a-custom-cursor-in-react-part-2-mathematical-explanation-2bf5</link>
      <guid>https://forem.com/germavinsmoke/how-to-create-a-custom-cursor-in-react-part-2-mathematical-explanation-2bf5</guid>
      <description>&lt;p&gt;If you’re looking for the source code then it’s available in the video 😉&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/VSZhw54yO3I"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Please support by watching this video 😢&lt;/p&gt;

&lt;p&gt;This article is mainly focused on the mathematical part of the cursor animation (cursor outline). &lt;a href="https://dev.to/germavinsmoke/how-to-create-a-custom-cursor-in-react-part-1-4fio"&gt;Part 1&lt;/a&gt; of the article was completely related to the code part if you want to see how it is working then you can follow it.&lt;/p&gt;

&lt;p&gt;The main part revolves around this function —&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvb2oe5ut0yl5bpgkgkj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvb2oe5ut0yl5bpgkgkj.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; also provides us with a timestamp variable which we can use to see after what time interval our recursive function is being called.&lt;/p&gt;

&lt;p&gt;We also need to store the &lt;strong&gt;x&lt;/strong&gt; and &lt;strong&gt;y&lt;/strong&gt; points every time this function is called. So, for that, we can create a function that can store all these 3 properties. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ee13m6odlu72dd7u9eh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ee13m6odlu72dd7u9eh.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to tweak our &lt;strong&gt;animateOutline&lt;/strong&gt; function also in order to get the desired output. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv41hvdyyt4szbemdxek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv41hvdyyt4szbemdxek.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are pushing the &lt;strong&gt;coordinate object&lt;/strong&gt; inside the coordinates &lt;strong&gt;array&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;New conditions have been added to stop the &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; function from calling it again. As per the condition, we will call it recursively only till the time &lt;strong&gt;cursor outline’s coordinate&lt;/strong&gt; aren’t equal to the &lt;strong&gt;cursor dot’s coordinate&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We will console log when the coordinates become equal. We’ll be using &lt;code&gt;console.table&lt;/code&gt; function because provides a nice tabular view of the output. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffyv2mxp46sgqzv5hdsah.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffyv2mxp46sgqzv5hdsah.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhruy6rau0746qa16sak.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhruy6rau0746qa16sak.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are few things which we can conclude from this data —&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The difference between the timestamps is almost constant, that is, 16–17ms. If you read &lt;a href="http://www.javascriptkit.com/javatutors/requestanimationframe.shtml" rel="noopener noreferrer"&gt;this&lt;/a&gt; article then you’ll know that it’s simulating 60FPS (1000/60). This 1000ms divided by 60 is equal to 16.67ms.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The data points have a huge difference in the initial phase of the animation but the difference reduces as time increases.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93t0g7etgdtkibeswu0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93t0g7etgdtkibeswu0w.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are adding the new value and the previous value. &lt;strong&gt;endX&lt;/strong&gt; is constant so if we subtract the &lt;strong&gt;x&lt;/strong&gt; from it after every iteration the numerator will keep on decreasing. And eventually it becomes somewhat near to 0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttb8p4b4r8pt45sul6bj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttb8p4b4r8pt45sul6bj.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frp6nv0z6ry0nbvf5zan7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frp6nv0z6ry0nbvf5zan7.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we plot &lt;em&gt;x points&lt;/em&gt; with respect to timestamp then we will get a graph like this  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzunaq6opuvvn2ah6bz1q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzunaq6opuvvn2ah6bz1q.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Somewhat looks like a logarithmic graph and ease-out cubic bezier function. Increases quickly in the initial phase and then the increment rate decreases.&lt;/p&gt;

&lt;p&gt;And that’s it, this is how we are able to achieve this smooth ease-out type of transition with the help of javascript. 🤩🥳 &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>How to create a custom cursor in React Part — 1</title>
      <dc:creator>GermaVinsmoke</dc:creator>
      <pubDate>Sat, 19 Jun 2021 13:41:19 +0000</pubDate>
      <link>https://forem.com/germavinsmoke/how-to-create-a-custom-cursor-in-react-part-1-4fio</link>
      <guid>https://forem.com/germavinsmoke/how-to-create-a-custom-cursor-in-react-part-1-4fio</guid>
      <description>&lt;p&gt;&lt;strong&gt;P.S — No modules were used while writing this code&lt;/strong&gt; 😆&lt;/p&gt;

&lt;p&gt;If you’re looking for the source code then it’s available in the video 😉&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/VSZhw54yO3I"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Please support by watching this video 😢&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic HTML — CSS layout of the cursor
&lt;/h2&gt;

&lt;p&gt;We’re gonna start with writing the &lt;strong&gt;JSX(HTML)&lt;/strong&gt; for cursor dot and cursor outline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3swrmb3kfhu1i3enb3cn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3swrmb3kfhu1i3enb3cn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We also created the &lt;code&gt;ref&lt;/code&gt; for these elements so that we can access the DOM elements later on.&lt;/p&gt;

&lt;p&gt;Next, we’re gonna add the &lt;strong&gt;CSS&lt;/strong&gt; styling to these elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnnzo98yo8nyytpqb8n8o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnnzo98yo8nyytpqb8n8o.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cursor: none&lt;/code&gt; is added to the universal selector &lt;code&gt;*&lt;/code&gt; because we want to hide the default cursor.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pointer-events: none&lt;/code&gt; so that this element doesn’t become a target of the pointer-events. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events" rel="noopener noreferrer"&gt;MDN pointer-events&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;position&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;absolute&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;top&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%;&lt;/span&gt;
&lt;span class="nt"&gt;left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%;&lt;/span&gt;
&lt;span class="nt"&gt;transform&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;translate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-50&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;-50&lt;/span&gt;&lt;span class="o"&gt;%);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet is used to move both elements in the centre.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;opacity: 1;&lt;/code&gt; is used so that later on we can hide and show our cursor based on &lt;code&gt;mouseenter&lt;/code&gt; and &lt;code&gt;mouseleave&lt;/code&gt; event. That’s why &lt;code&gt;transition&lt;/code&gt; is also used on the &lt;code&gt;opacity&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Transition on &lt;code&gt;transform&lt;/code&gt; is used so that we can increase and reduce the size of the dot and outline based on some mouse events (will soon get to know which one 😉).&lt;/p&gt;

&lt;p&gt;It’ll look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fubu9ok7sqrleabrv4icz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fubu9ok7sqrleabrv4icz.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding images to show cursor hover effect
&lt;/h2&gt;

&lt;p&gt;We’re gonna add some images to show that smooth cursor hover transition.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncmsvw1b22wwu5jrqq9u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncmsvw1b22wwu5jrqq9u.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Created this &lt;code&gt;&amp;lt;Link /&amp;gt;&lt;/code&gt; component which can be reused for displaying the images.&lt;/p&gt;

&lt;p&gt;Now, we need to import this into our &lt;code&gt;&amp;lt;Cursor /&amp;gt;&lt;/code&gt; component and pass the images. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu0w3sazwn3uputweisbj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu0w3sazwn3uputweisbj.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ve added &lt;code&gt;ref&lt;/code&gt; to its container because we’ll be adding the mouse events to all those images.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;getImage&lt;/code&gt; is a util function that I created in order to get the images based on the index value provided by the map function. You can find the function in the source code (not adding any image because it isn’t that important. Sorry &lt;code&gt;getImage&lt;/code&gt; function! 😥). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonus Points 🤩&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The import statement’s path&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In order to use that I used &lt;code&gt;jsconfig.json&lt;/code&gt;. You can add this file at the root of your project and add the &lt;code&gt;baseUrl&lt;/code&gt; property inside &lt;code&gt;compilerOptions&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faeam0pmlpzoq77bfhoh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faeam0pmlpzoq77bfhoh5.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The &lt;code&gt;[...Array(4).keys()]&lt;/code&gt; code snippet&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;Array(4)&lt;/code&gt; will create an empty array of size 4.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;keys()&lt;/code&gt;&lt;/strong&gt; method returns a new &lt;strong&gt;Array Iterator&lt;/strong&gt; object that contains the keys for each index in the array.&lt;/p&gt;

&lt;p&gt;And spreading the array will give us an array — &lt;code&gt;[0, 1, 2, 3]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Okay, let’s get back to what we were doing 😅.&lt;/p&gt;

&lt;p&gt;The final thing is to add a bit of styling to our images container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdqh9ock2mtp4hyrmrym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdqh9ock2mtp4hyrmrym.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now the final outcome will look something like this —&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6yga51kat9e48ver4g84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6yga51kat9e48ver4g84.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Animation to our cursor
&lt;/h2&gt;

&lt;p&gt;Finally, the time has come to add the animation to our cursor (poor cursor sitting alone at the centre of the screen 😥).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding ref variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We need to add some more &lt;code&gt;refs&lt;/code&gt; to our &lt;strong&gt;Cursor&lt;/strong&gt; component so that we can update the changes.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodudpqgveq4qxyuti75q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodudpqgveq4qxyuti75q.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;delay&lt;/strong&gt; will be used as a factor by which we will change how quickly or slowly the cursor outline should follow the cursor dot. A higher number means slow and vice versa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;cursorVisible&lt;/strong&gt; will help in toggling the visibility of the cursor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;cursorEnlarged&lt;/strong&gt; will help in toggling the size of the cursor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;endX&lt;/strong&gt; is the X-position of the cursor dot. We will be saving the X position of the dot in this variable. It is initialised with &lt;code&gt;window.innerWidth/2&lt;/code&gt; because that’s mid of X-axis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;endY&lt;/strong&gt; is the Y-position of the cursor dot. We will be saving the Y position of the dot in this variable. The concept is same as &lt;strong&gt;endX&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_x&lt;/strong&gt; is the X-position of the cursor outline. We will be saving the X position of the outline in this variable. It’s initialised with 0 because we want to show movement animation. (The outline coming from the top left corner of the screen to the middle point where the dot is present at the start of the application).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_y&lt;/strong&gt; is the Y-position of the cursor outline. We will be saving the Y position of the outline in this variable. The concept is same as &lt;strong&gt;_x&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;requestRef&lt;/strong&gt; will save an ID returned from one important function (will see it when we add an animation to the cursor outline). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding cursor toggle functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98rj5236xx61xx5s2n82.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98rj5236xx61xx5s2n82.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;toggleCursorVisibility&lt;/strong&gt; — If the cursor is visible then we will change the opacity to 1 otherwise we will change it to 0. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;toggleCursorSize&lt;/strong&gt; — If the cursorEnlarged is true then we will decrease the size of the dot and increase the size of the outline. In case of a false, we will change it back to the original size.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Adding over, out, enter, leave mouse events&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fllxr2c4pp7ocgeoc5yqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fllxr2c4pp7ocgeoc5yqn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;‘mouseover’&lt;/strong&gt; — The &lt;strong&gt;mouseover&lt;/strong&gt; event is fired when the cursor comes on top of the element or its children.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;‘mouseout’&lt;/strong&gt; — The &lt;strong&gt;mouseout&lt;/strong&gt; event is fired when the cursor is not on top of the element or its children.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;‘mouseleave’&lt;/strong&gt; — The &lt;strong&gt;mouseleave&lt;/strong&gt; event is fired when we leave the page viewport.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;‘mouseenter’&lt;/strong&gt; — The &lt;strong&gt;mouseenter&lt;/strong&gt; event is fired when we enter the page viewport.&lt;/p&gt;

&lt;p&gt;Now, we can pass &lt;strong&gt;mouseOverEvent&lt;/strong&gt; and &lt;strong&gt;mouseOutEvent&lt;/strong&gt; to our image component. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkp73xmcbt9j3aeieh14y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkp73xmcbt9j3aeieh14y.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These functions will be called whenever the mouse cursor comes on top of the image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding mousemove event&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0bib52lgss0f0wox0gij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0bib52lgss0f0wox0gij.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first thing we need to make sure is that our cursor is visible, that’s why we’ve updated the &lt;strong&gt;currentVisible&lt;/strong&gt; and called the &lt;strong&gt;toggleCursorVisibility&lt;/strong&gt; function.&lt;/p&gt;

&lt;p&gt;Then, we are taking the current position of the cursor with the help of &lt;strong&gt;pageX&lt;/strong&gt; and &lt;strong&gt;pageY&lt;/strong&gt;. The next step is to update the top and left property of the dot cursor to show it moving around on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P.S&lt;/strong&gt; — This &lt;a href="https://stackoverflow.com/questions/6073505/what-is-the-difference-between-screenx-y-clientx-y-and-pagex-y" rel="noopener noreferrer"&gt;StackOverflow&lt;/a&gt; answer has a very good explanation about the difference between &lt;strong&gt;clientX&lt;/strong&gt; and &lt;strong&gt;pageX&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding cursor outline animation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gjzklaxac396ecszsgk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gjzklaxac396ecszsgk.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a special recursive function that we call inside &lt;code&gt;requestAnimationFrame&lt;/code&gt; function. In this function, we update the position of &lt;strong&gt;cursor outline&lt;/strong&gt; with respect to the position of &lt;strong&gt;cursor dot&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The mathematical explanation for this is present in part 2 of the article.&lt;/p&gt;

&lt;p&gt;This &lt;a href="http://www.javascriptkit.com/javatutors/requestanimationframe.shtml" rel="noopener noreferrer"&gt;article&lt;/a&gt; is great to understand how &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; works and why it was created.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calling all event functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flh98n6c0ri86g8aw0fr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flh98n6c0ri86g8aw0fr3.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can call all our event functions inside &lt;code&gt;useEffect&lt;/code&gt; (componentDidMount). At the time of unmounting, we should remove all the event listeners and also cancel the requestAnimationFrame using &lt;strong&gt;cancelAnimationFrame&lt;/strong&gt; function.&lt;/p&gt;

&lt;p&gt;And with all these functions, our poor cursor can finally move 🥳 &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7m3f6sjii8gn6pns44r9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7m3f6sjii8gn6pns44r9.gif" alt="2021-06-13 22-32-53"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://germavinsmoke.medium.com/how-to-create-a-custom-cursor-in-react-part-2-mathematical-explanation-2193b52c43ba" rel="noopener noreferrer"&gt;Part 2&lt;/a&gt; of the article is having a little bit of mathematical explanation. So you can check it out if you want to.&lt;/p&gt;

&lt;p&gt;Some of the important links —  &lt;/p&gt;

&lt;p&gt;MDN requestAnimationFrame — &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;StackOverflow answer on requestAnimationFrame — &lt;a href="https://stackoverflow.com/questions/52212703/using-requestanimationframe-in-react/52213728" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/52212703/using-requestanimationframe-in-react/52213728&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using requestAnimationFrame in React — &lt;a href="https://css-tricks.com/using-requestanimationframe-with-react-hooks/" rel="noopener noreferrer"&gt;https://css-tricks.com/using-requestanimationframe-with-react-hooks/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using event listeners in React — &lt;a href="https://www.pluralsight.com/guides/event-listeners-in-react-components" rel="noopener noreferrer"&gt;https://www.pluralsight.com/guides/event-listeners-in-react-components&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;VanillaJS codepen for custom cursor — &lt;a href="https://codepen.io/kjbrum/pen/qooQJJ" rel="noopener noreferrer"&gt;https://codepen.io/kjbrum/pen/qooQJJ&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>How to create a page load animated loader in React</title>
      <dc:creator>GermaVinsmoke</dc:creator>
      <pubDate>Sun, 06 Jun 2021 17:11:30 +0000</pubDate>
      <link>https://forem.com/germavinsmoke/how-to-create-a-page-load-animated-loader-in-react-3cen</link>
      <guid>https://forem.com/germavinsmoke/how-to-create-a-page-load-animated-loader-in-react-3cen</guid>
      <description>&lt;p&gt;We’re gonna see how to create an animated loader that comes at the time of page load.&lt;br&gt;
Basically, it’s equivalent to Javascript’s &lt;code&gt;load&lt;/code&gt; event. The &lt;code&gt;load&lt;/code&gt; event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;load&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;page is fully loaded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/HHmmOH5Ep3M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We need to add our &lt;strong&gt;loaders&lt;/strong&gt; HTML and CSS inside the &lt;code&gt;index.html&lt;/code&gt; file present inside the &lt;code&gt;public&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"loader-wrapper"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"loader"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the react app is mounted in &lt;strong&gt;root&lt;/strong&gt; div, so we need to add our loader HTML part inside the &lt;strong&gt;root&lt;/strong&gt; div.&lt;br&gt;
Then, we can add the CSS part inside the same file, inside the &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;.loader-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#0b0b0b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="py"&gt;place-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;.loader&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#e3e3e3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;border-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#3498db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;140px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;140px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;spin&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;linear&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;spin&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;360deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it, it’ll create a page loader for your react application which will only come up whenever the website is first opened up.&lt;/p&gt;

&lt;p&gt;It is quite different from the one which we use in the case of &lt;code&gt;React.lazy&lt;/code&gt; and &lt;code&gt;Suspense&lt;/code&gt; because in that, it uses the &lt;code&gt;fallback&lt;/code&gt; property of &lt;code&gt;Suspense&lt;/code&gt; which is visible every time the &lt;strong&gt;route&lt;/strong&gt; of our page changes and it’s a new &lt;strong&gt;route&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Source code of the application - &lt;a href="https://github.com/GermaVinsmoke/react-page-loader"&gt;react-page-loader&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
