<?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: Zenveus</title>
    <description>The latest articles on Forem by Zenveus (@zenveus).</description>
    <link>https://forem.com/zenveus</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%2Forganization%2Fprofile_image%2F2848%2F26dbca3d-18b3-4e85-9c6e-3ce78c8f8a92.jpg</url>
      <title>Forem: Zenveus</title>
      <link>https://forem.com/zenveus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/zenveus"/>
    <language>en</language>
    <item>
      <title>Web Animations</title>
      <dc:creator>Hamza Shahab</dc:creator>
      <pubDate>Thu, 27 Aug 2020 08:39:26 +0000</pubDate>
      <link>https://forem.com/zenveus/web-animations-2n8a</link>
      <guid>https://forem.com/zenveus/web-animations-2n8a</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Animations play an important role in our day to day internet surfing. They make the online loading experience more entertaining for the users and develops interests among them.&lt;/p&gt;

&lt;p&gt;They are a powerful tool and are quite effective in making the online websites more interactive and engaging for the visitors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"Animation is the art of bringing life to images and graphical objects"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Animation?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"A method in which pictures are manipulated to appear as moving images"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this blog, I'll be focusing purely on CSS Animations. So let's get started!&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Animation
&lt;/h1&gt;

&lt;p&gt;Elements in web page can be shifted, rotated and transformed using CSS Animations. They can be moved across the page and interacted in all sorts of interesting ways.&lt;/p&gt;

&lt;p&gt;In order to develop a better understanding of CSS Animations, let's understand what keyframes are :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Keyframes
&lt;/h2&gt;

&lt;p&gt;In animation, &lt;strong&gt;&lt;em&gt;"A keyframe is a drawing that defines the starting and ending point of any smooth transition."&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see how we can implement a decent animation using keyframes, in an example below:&lt;/p&gt;

&lt;p&gt;For that we'll be needing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A static svg image&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%2Fi%2Fy16kos6kwbiq7xbt5ydm.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%2Fi%2Fy16kos6kwbiq7xbt5ydm.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;and... a bit of css xD&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The svg image is divided into smaller parts and each part is grouped and given a specific id which will be later used in CSS.&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%2Fi%2Fqk0ztqrlnq09s0u9uiyy.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%2Fi%2Fqk0ztqrlnq09s0u9uiyy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now here's how we'll modify the code to make our asset move the way we want!&lt;/p&gt;

&lt;p&gt;We'll be creating separate keyframes for the transition and movement of different parts:&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Barbell
&lt;/h1&gt;

&lt;p&gt;The following code will aid in the vertical motion of the barbell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes barbell {
  from {
    transform: translateY(0%);
  }
  to {
    transform: translateY(42%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is then integrated to the corresponding part in svg by assigning the keyframe to the &lt;code&gt;animation&lt;/code&gt; attribute in &lt;code&gt;#Barbell&lt;/code&gt; selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Barbell {
  width: 700px;
  height: auto;
  margin: 0;
  padding: 0;
  animation: barbell 1s ease-in-out 6 alternate;
  transform-origin: center;
  transform-box: fill-box;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  2. Arms
&lt;/h1&gt;

&lt;p&gt;This one's a bit tricky, so fasten your seat belts xD&lt;br&gt;
To illustrate the bending motion of the arms we further subdivided it to arm &amp;amp; forearm pair.&lt;/p&gt;
&lt;h2&gt;
  
  
  Forearm
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes foreArmLeft {
  from {
    transform: rotate(0deg) translateY(0%) translateX(0%) scaleY(1);
  }
  to {
    transform: rotate(8deg) translateY(35%) translateX(-63%) scaleY(0.65);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;translate(35%)&lt;/code&gt; adds a bit of vertical motion to the forearm to depict the lifting of barbell while the &lt;code&gt;rotate(8deg)&lt;/code&gt; illustrates the bending motion. This is then integrated to the forearm selector &lt;code&gt;#ForeArmLeft&lt;/code&gt; as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#ForeArmLeft {
  animation: foreArmLeft 1s ease-in-out 6 alternate;
  transform-origin: bottom;
  transform-box: fill-box;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Upper Arm
&lt;/h2&gt;

&lt;p&gt;The code below aids in moving the upper arm of the brain diagonally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes upperArmLeft{
  from {
    transform: translateY(0%) translateX(0%);
  }
  to {
    transform: translateY(270%) translateX(-60%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  3. Face
&lt;/h1&gt;

&lt;p&gt;The following 2 keyframes contribute to the transition of happy and sad moods of the brain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes faceHappy{
  from{
    opacity: 1;
    transform: translateY(0%);
  }
  to{
    opacity: 0;
    transform: translateY(3%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes faceSad{
  from{
    opacity: 0;
    transform: translateY(0%);
  }
  to{
    opacity: 1;
    transform: translateY(3%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  4. Body
&lt;/h1&gt;

&lt;p&gt;The slight vertical motion of the body representing the brain's efforts to lift the barbell is created with the following piece of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes body {
  from {
    transform: translateY(0%);
  }
  to {
    transform: translateY(5%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voila! Our animation is now ready... Let's have a look!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/hamzashahab1610-the-decoder/embed/ExKmZzJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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

</description>
      <category>css</category>
      <category>html</category>
      <category>react</category>
      <category>animations</category>
    </item>
    <item>
      <title>Routing with React Router V6</title>
      <dc:creator>Zaid Akhter</dc:creator>
      <pubDate>Wed, 17 Jun 2020 15:56:47 +0000</pubDate>
      <link>https://forem.com/zenveus/routing-with-react-router-v6-6b1</link>
      <guid>https://forem.com/zenveus/routing-with-react-router-v6-6b1</guid>
      <description>&lt;p&gt;React Router has been the go to routing solution for most react applications. Is simple to use and offers tons of features. If you've used react router before you'd be pleased to know it just got better with its next major version, version 6. Now, react router version 6 is currently in alpha. But it's expected to launch a stable version soon. Also you should know this post is for people already familiar with react router.&lt;/p&gt;

&lt;p&gt;Now lets talk about some key changes with react router version 6. First of all, it has smaller bundle sizes but still manages to pack in more functionality.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;Run the following command to install with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm i react-router@next react-router-dom@next
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or with yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn add react-router@next react-router-dom@next
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;&amp;lt;Route/&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In previous versions, you could use the route element like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;render&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&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;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These methods don't work in version 6. In version 6, you can use the &lt;code&gt;&amp;lt;Route/&amp;gt;&lt;/code&gt; element as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;&amp;lt;Routes/&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;Switch/&amp;gt;&lt;/code&gt; component has been replaced by &lt;code&gt;&amp;lt;Routes/&amp;gt;&lt;/code&gt; in version 6. So you can do something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/user"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is important to note that all &lt;code&gt;&amp;lt;Route/&amp;gt;&lt;/code&gt; elements must be wrapped in &lt;code&gt;&amp;lt;Routes/&amp;gt;&lt;/code&gt; element. Also we no longer need to use the &lt;code&gt;exact&lt;/code&gt; prop on &lt;code&gt;&amp;lt;Route/&amp;gt;&lt;/code&gt;. Routes are matched exactly by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nesting Routes
&lt;/h2&gt;

&lt;p&gt;Nesting routes in older versions of react router was a bit non-intuitive. But version 6 makes it easier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"users"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Users&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UsersIndex&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;":id"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserProfile&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"me"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OwnUserProfile&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;nav&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"me"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;My Profile&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;nav&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Outlet&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;The &lt;code&gt;&amp;lt;Outlet/&amp;gt;&lt;/code&gt; component in &lt;code&gt;Users&lt;/code&gt; component serves as a placeholder. It will render a component depending on the current location.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object-based Routes
&lt;/h2&gt;

&lt;p&gt;Version 6 allows us to define routes as JavaScript objects using the &lt;code&gt;useRoutes()&lt;/code&gt; hook which accepts an array of route objects. A route object has the same properties as a &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt;. For example the routes above can also be defined as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRoutes&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="c1"&gt;// element. The `children` is just an array of child routes.&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Users&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt;
      &lt;span class="na"&gt;children&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UsersIndex&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserProfile&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OwnUserProfile&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&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="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;element&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;It is important to note that the &lt;code&gt;useRoutes()&lt;/code&gt; hook must be in context of &lt;code&gt;&amp;lt;BrowserRouter/&amp;gt;&lt;/code&gt;. That is why we removed it from the &lt;code&gt;App&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;useNavigate()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;React router version 6 replaces the &lt;code&gt;useHistory()&lt;/code&gt; hook with the &lt;code&gt;useNavigate()&lt;/code&gt; hook. Which can be used as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;navigate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useNavigate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Go Home
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;You can pass a second optional parameter in &lt;code&gt;navigate&lt;/code&gt;. It will be an object and it can contain &lt;code&gt;state&lt;/code&gt; if you want to pass in state. You can also pass in &lt;code&gt;replace:true&lt;/code&gt; to mimic the behavior of &lt;code&gt;history.replace()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Alternatively, you can also pass in a positive or negative integer in the &lt;code&gt;navigate&lt;/code&gt; function. This will navigate us forward or backwards in the browser history stack. For example &lt;code&gt;navigate(1)&lt;/code&gt; will take us 1 page forward. Similarly, &lt;code&gt;navigate(-2)&lt;/code&gt; will take us 2 pages back.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;To wrap up react router version 6 brings cool new features. And makes it more intuitive to use. There are some more minor features which I haven't mentioned. But I have covered the main features coming in react router version 6. And that should be enough to get you started with it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>reactrouter</category>
      <category>navigation</category>
    </item>
    <item>
      <title>Creating a Localized Online Shop with Gatsby, Contentful &amp; Foxy Cart</title>
      <dc:creator>Kumail Pirzada</dc:creator>
      <pubDate>Wed, 20 May 2020 07:00:40 +0000</pubDate>
      <link>https://forem.com/zenveus/creating-a-localized-online-shop-with-gatsby-contentful-foxy-cart-39bf</link>
      <guid>https://forem.com/zenveus/creating-a-localized-online-shop-with-gatsby-contentful-foxy-cart-39bf</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;I've had the pleasure of working with Gatsby for static websites multiple times now. However, this particular project I'm working on stands out as a very interesting approach to creating a E-commerce shop for the real-world by fully utilizing the power of JAMstack.&lt;/p&gt;

&lt;p&gt;This project consists of &lt;em&gt;three&lt;/em&gt; components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Gatsby&lt;/em&gt; for Static Site Generation&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Contentful&lt;/em&gt; for Data storage + structure management&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Foxy.io&lt;/em&gt; for remote Shopping Cart management&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  So how does it work?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Gatsby:
&lt;/h4&gt;

&lt;p&gt;We use Gatsby for static site generation, meaning, everything is compiled and built once and served. This includes (most) HTTP requests as well. We create pages dynamically, by fetching the data from Contentful and looping over the data.&lt;/p&gt;

&lt;p&gt;Gatsby provides us with a lot of helper '&lt;em&gt;plugins&lt;/em&gt;', such as Gatsby Image, which uses Sharp under-the-hood to render images. This is one of the things that makes Gatsby sites blazing fast, and provides an amazing experience for the end-user as well as the developer.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Contentful:
&lt;/h4&gt;

&lt;p&gt;Contentful can be called the 'brain' of our application, where Gatsby was the body. Basically, we create multiple data structures for our data in Contentful, and link them together so it is a breeze to get the required data through the GraphQL API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The data structures:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Localization:&lt;/strong&gt;&lt;br&gt;
In the app I worked on, we had three languages, English, Deutsch and French. For each item that we added to Contentful, we also added the Deutsch and French versions for it and provided a common fallback (English). This makes it easy to query for the required version of each item through the GraphQL API.&lt;/p&gt;

&lt;p&gt;Secondly, we also have individual translated strings for most items throughout the site. This is for generalization where we don't need to create a whole new page or component, so we use a single string data structure. We fetch all these translated strings at build time and store them in our Redux store, and use a selector to get the required string according to the locale where we need.&lt;br&gt;
Some other data structures specific to the locale include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Continent&lt;/li&gt;
&lt;li&gt;Country, linked to continent (Country code, name, currency)&lt;/li&gt;
&lt;li&gt;Currency, linked to the country (Currency name)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Products &amp;amp; Categories:&lt;/strong&gt;&lt;br&gt;
We have different products with different categories. Each category represents multiple products, for example a "bag" category can represent shoulder bags, handbags, etc. Each product, i.e. shoulder bag can have multiple &lt;em&gt;variants&lt;/em&gt;, such as black, white, with strap, without strap, and so on..&lt;br&gt;
Each Contentful item is linked to ensure we have full knowledge of our tree when fetching from the GraphQL API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt;&lt;br&gt;
Even though our end result is a static website, we don't have "static" hardcoded pages. Each page is defined in Contentful, with multiple sections as data structures. Each section can have images, videos, headings, text, etc. depending on the structure. During build time, we loop through all contentful pages and fetch the sections for each and display them using the components we have already created in Gatsby. This means we don't need to modify code to move around sections, add new sections or pages, etc. We can simply make the required changes in Contentful and see the changes in pages when we build our application.&lt;/p&gt;

&lt;p&gt;Apart from these, we also have multiple small data structures such as footer information, etc. that I won't go into more detail here.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Foxy.io:
&lt;/h4&gt;

&lt;p&gt;Foxy provides a remote shopping cart which we can easily integrate into our website to implement an existing shopping cart into our application.&lt;br&gt;
This means, we do not need to create our custom cart and manage items, payment processing, updating database, etc. etc.&lt;br&gt;
In our example, we have created a shopping cart inside our website for 'costmetic' purposes, which we link to Foxy on checkout. All we need to do is create a form that submits the selected products with their information to our Foxy checkout page, which handles the rest.&lt;br&gt;
We can customize the remote cart to our liking through it's dashboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;This was a &lt;em&gt;VERY&lt;/em&gt; high-level view of how I created an online shop with Gatsby, Contentful &amp;amp; Foxy.io. A more detailed blog may follow at a later date.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>contentful</category>
      <category>foxy</category>
      <category>react</category>
    </item>
  </channel>
</rss>
