<?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: Ruben</title>
    <description>The latest articles on Forem by Ruben (@rleija_).</description>
    <link>https://forem.com/rleija_</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%2F38217%2F881477fe-a3d7-4dad-8549-aba8ce584c7d.jpg</url>
      <title>Forem: Ruben</title>
      <link>https://forem.com/rleija_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rleija_"/>
    <language>en</language>
    <item>
      <title>Code splitting React router with React Lazy and React Suspense</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Mon, 11 Nov 2019 16:14:22 +0000</pubDate>
      <link>https://forem.com/rleija_/code-splitting-react-router-with-react-lazy-and-react-suspense-3i96</link>
      <guid>https://forem.com/rleija_/code-splitting-react-router-with-react-lazy-and-react-suspense-3i96</guid>
      <description>&lt;p&gt;&lt;em&gt;original post @ &lt;a href="https://linguinecode.com/post/code-splitting-react-router-with-react-lazy-and-react-suspense" rel="noopener noreferrer"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JavaScript is fast. But before it becomes fast, your browser has to do a lot of work before it serves your fast JavaScript application.&lt;/p&gt;

&lt;p&gt;One of the bottlenecks for JavaScript is the bundle size.&lt;/p&gt;

&lt;p&gt;The problem with a huge bundle file size is the increase in TTI (time to interactive).&lt;/p&gt;

&lt;p&gt;TTI is the result of how long does it take for the user to actually be able to use the application or site.&lt;/p&gt;

&lt;p&gt;This is measured in time (milliseconds, seconds, minutes, etc).&lt;/p&gt;

&lt;p&gt;Let’s take a look at CNN.com and throttle the network to a slow 3G.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F06%2F30120550%2Fcnn-js-network-load-time-slow-3g-1024x768.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F06%2F30120550%2Fcnn-js-network-load-time-slow-3g-1024x768.jpg" alt="CNN slow 3G network test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In each row you can see the JavaScript file being downloaded and executed.&lt;/p&gt;

&lt;p&gt;You can also see the compressed size, the uncompressed size, and how long it took to be completed.&lt;/p&gt;

&lt;p&gt;If we open on their cnn-footer-lib.min.js file, you’ll see that there is nothing minified about it.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F06%2F30121135%2Fcnn-minified-footer-code.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F06%2F30121135%2Fcnn-minified-footer-code.jpg" alt="CNN minified footer JS code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And it looks like it contains a lot of the logic for the site in that 1 file.&lt;/p&gt;

&lt;h2&gt;
  
  
  React + Webpack = 1 big bundle file
&lt;/h2&gt;

&lt;p&gt;99% of the time when you’re developing in React, you’re going to be using Webpack to help you bundle up everything into a nice package.&lt;/p&gt;

&lt;p&gt;Webpack at it’s core, is meant to help hot reload during development, and bundle all your JavaScript files into 1 or multiple JS files.&lt;/p&gt;

&lt;p&gt;But if you’re developing React, you’re typically aiming for a single page application, which you’ll typically have 1 JavaScript bundle file.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F06%2F30141103%2Fwebpack-bundle-output-illustration2-1024x768.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F06%2F30141103%2Fwebpack-bundle-output-illustration2-1024x768.jpg" alt="Webpack bundle output into a single file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your React files aren’t big, it’s actually some of the smallest. But as you install React, and other third party libraries that bundle output gets bigger.&lt;/p&gt;

&lt;p&gt;And loading a 500kb file isn’t a pretty user experience.&lt;/p&gt;

&lt;p&gt;To give a better user experience, we can do a technique called dynamic importing, also known as lazy loading.&lt;/p&gt;

&lt;p&gt;Also known as lazy loading.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Lazy loading React components
&lt;/h2&gt;

&lt;p&gt;The concept of lazy loading our React JS files is really simple.&lt;/p&gt;

&lt;p&gt;Load the minimal code to the browser that will render a page.&lt;/p&gt;

&lt;p&gt;Load additional small chunks of code when needed.&lt;/p&gt;

&lt;p&gt;By loading less JavaScript code to the browser, that will default to better performance and better TTI results.&lt;/p&gt;

&lt;p&gt;The concept of lazy loading may apply to any JavaScript application, but for the sake of simplicity will keep it to React talk.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code splitting with React
&lt;/h2&gt;

&lt;p&gt;In today’s example, I will be starting off from a previous article that explains &lt;a href="https://linguinecode.com/post/add-react-router-to-react" rel="noopener noreferrer"&gt;how to get started with React router&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One thing to note, is that the previous work is using Create React App.&lt;/p&gt;

&lt;p&gt;And Create React App has already enabled Webpack to perform code splitting.&lt;/p&gt;

&lt;p&gt;The goal now is to utilize the code splitting capabilities, and lazy loading technique, and apply it to the React app.&lt;/p&gt;

&lt;p&gt;Another reason I want to use a previous example is because I’m going to demonstrate how to do route base code splitting with React.&lt;/p&gt;

&lt;p&gt;I only want to load the JavaScript code that is needed to render a page, at that given time.&lt;/p&gt;

&lt;p&gt;And I will be using React lazy and Suspense to load other React files as a user navigates through the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lazy loading with React Suspense and React lazy
&lt;/h2&gt;

&lt;p&gt;Before we jump into implementing the lazy load code, let’s do a quick recap of the current app.&lt;/p&gt;

&lt;p&gt;Here are the current pages the cat application has.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01005936%2Fcat-pages-1024x768.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01005936%2Fcat-pages-1024x768.jpg" alt="Cat application pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have 3 pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A list of cats&lt;/li&gt;
&lt;li&gt;  A form to add a cat name&lt;/li&gt;
&lt;li&gt;  A single view for a cat&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s take a quick look at the current code.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28182350%2Freact-router-config-file.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28182350%2Freact-router-config-file.png" alt="React router config file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The file above is a route configuration that just attaches a path to a page.&lt;/p&gt;

&lt;p&gt;The next file is the App.js file that grabs the route configuration file and creates routes out of it.&lt;/p&gt;

&lt;p&gt;Look at lines 31-44.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01010751%2Freact-router-loop-highlight-535x1024.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01010751%2Freact-router-loop-highlight-535x1024.png" alt="Rendering React routes inside a map loop"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It goes through a map loop to create a React route component.&lt;/p&gt;

&lt;p&gt;Now let’s take a quick look at the React developer tools and see how it looks at initial render.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01011146%2Freact-dev-tools-react-router.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01011146%2Freact-dev-tools-react-router.jpg" alt="Inspecting React router output with React developer tools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;React renders every page route. Even when we don’t need it at the moment.&lt;/p&gt;

&lt;p&gt;Let’s take a quick look at the network tab for JS files.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01011547%2Fnetwork-tab-main-bundle.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F01011547%2Fnetwork-tab-main-bundle.jpg" alt="React output network inspection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The main.[name].chunk.js file is basic Webpack initial code. The big file size is the React cat application.&lt;/p&gt;

&lt;p&gt;Our goal is to make our initial load smaller and load in chunks when needed.&lt;/p&gt;

&lt;p&gt;Let’s start adding the code!&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding lazy loading to React router
&lt;/h2&gt;

&lt;p&gt;The first step I took, was to remove &lt;em&gt;route.js&lt;/em&gt; file.&lt;/p&gt;

&lt;p&gt;The second step was to modify the App.js file. Take a look at the highlighted areas only.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02120105%2Fcat-app-with-react-router-lazy-suspense-795x1024.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02120105%2Fcat-app-with-react-router-lazy-suspense-795x1024.png" alt="React router with lazy loading code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The highlighted areas shows where the code has changed a bit. Don’t worry I’ll break it down.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Import React router Switch component
&lt;/h3&gt;

&lt;p&gt;The first step I took to update the &lt;em&gt;App.js&lt;/em&gt; file was in line 5.&lt;/p&gt;

&lt;p&gt;I imported the Switch component from react router dom.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;Switch&lt;/em&gt; component is a unique React component, as it’s job is to only render a single route component.&lt;/p&gt;

&lt;p&gt;You will never see more than one.&lt;/p&gt;

&lt;p&gt;In the React developer tool image above, you might have seen 3 routes. Let’s take a look at the developer tool again to see how many routes will render.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02121035%2Freact-router-switch-component-dev-tools.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02121035%2Freact-router-switch-component-dev-tools.jpg" alt="Inspecting react router with lazy loading on React developer tools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And as you navigate through the application, only 1 Route will ever show.&lt;/p&gt;

&lt;p&gt;This is helpful because there is no need to have additional code that doesn’t get used at that given time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Create React lazy Components
&lt;/h3&gt;

&lt;p&gt;In line 8 to 10, I created a React lazy components for each page.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02121438%2Freact-lazy-dynamic-import-1024x304.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02121438%2Freact-lazy-dynamic-import-1024x304.png" alt="React lazy with dynamic import code sample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;React lazy let’s you import dynamically a file and covert it into a regular React component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Use React Suspense component
&lt;/h3&gt;

&lt;p&gt;Before I use my React lazy components, I’m going to add the &lt;a href="https://linguinecode.com/post/how-react-suspense-works" rel="noopener noreferrer"&gt;React Suspense&lt;/a&gt; component as a wrapper.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02122621%2Freact-suspense-switch1-1024x542.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02122621%2Freact-suspense-switch1-1024x542.png" alt="Using React Suspense and React Router Switch component to add a fallback option and reduce amount of code and markup on render method."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://linguinecode.com/post/how-react-suspense-works" rel="noopener noreferrer"&gt;React Suspense&lt;/a&gt; is another component provided from the React library.&lt;/p&gt;

&lt;p&gt;The React Suspense component helps as a fallback option, to let your users know it’s loading.&lt;/p&gt;

&lt;p&gt;This is due to how dynamic importing works.&lt;/p&gt;

&lt;h4&gt;
  
  
  So what is dynamic importing?
&lt;/h4&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02123207%2Fstatic-import-vs-dynamic-import.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02123207%2Fstatic-import-vs-dynamic-import.png" alt="static importing vs dynamic importing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we take a look at the image above, I’ve given 2 different examples of using the keyword &lt;em&gt;import&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Even though it looks like the same, it’s not.&lt;/p&gt;

&lt;p&gt;The first import statement can only happen at the top of the file, and only accepts a literal string.&lt;/p&gt;

&lt;p&gt;This is good for importing modules that you’ll need in your code file.&lt;/p&gt;

&lt;p&gt;The second &lt;em&gt;import&lt;/em&gt; example, uses parenthesis, as you would use in a function.&lt;/p&gt;

&lt;p&gt;This let’s your code know that this will be treated asynchronously, and will return a promise.&lt;/p&gt;

&lt;p&gt;Since dynamic importing is asynchronous, that’s where React Suspense comes into play.&lt;/p&gt;

&lt;p&gt;Suspense will display the fallback option until the promise has completed.&lt;/p&gt;

&lt;p&gt;The promise in this case, is that a JavaScript file (React file) has been loaded and executed by the browser.&lt;/p&gt;

&lt;p&gt;This will happen as the user goes to each &lt;strong&gt;new&lt;/strong&gt; page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Add our React lazy component to a route
&lt;/h3&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02124314%2Freact-router-with-react-lazy-component-1024x427.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02124314%2Freact-router-with-react-lazy-component-1024x427.png" alt="Applying React lazy component to React route component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a fairly simple step.&lt;/p&gt;

&lt;p&gt;Inside my Switch component I’m defining my routes, with a path, and the React lazy component that I want to use.&lt;/p&gt;

&lt;p&gt;And I’m also passing properties down to each React lazy component, such my list of cats or a &lt;em&gt;onSubmit&lt;/em&gt; handler function.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;p&gt;What I’ve managed to do is grab the entire app and split them into smaller chunks.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02133253%2Freact-lazy-chunks-lazy-load-1024x768.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02133253%2Freact-lazy-chunks-lazy-load-1024x768.jpg" alt="Webpack producing smaller chunks illustration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is always going to be a main bundle JS file. But only 1 small chunk file will be downloaded.&lt;/p&gt;

&lt;p&gt;As the user navigates through the app and discovers new pages, other small chunks will be downloaded.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02124659%2Freact-lazy-load-output-1024x561.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F07%2F02124659%2Freact-lazy-load-output-1024x561.jpg" alt="JavaScript chunk files being loaded as discovering new pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method makes it easy for the browser to process, and execute.&lt;/p&gt;

&lt;p&gt;Smaller chunks of code equals faster TTI results (time to interactive).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Code splitting your React application will bring better performance, because it will only load the minimal code it needs to render a page.&lt;/p&gt;

&lt;p&gt;Thus bringing a better user experience, and making your users happy.&lt;/p&gt;

&lt;p&gt;Github code: &lt;a href="https://github.com/rleija703/react-examples/tree/master/examples/with-router-lazy-loading" rel="noopener noreferrer"&gt;React router with lazy loading&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Adding React router to your app</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Tue, 30 Apr 2019 12:47:49 +0000</pubDate>
      <link>https://forem.com/rleija_/adding-react-router-to-your-app-80b</link>
      <guid>https://forem.com/rleija_/adding-react-router-to-your-app-80b</guid>
      <description>&lt;p&gt;&lt;em&gt;original post @ &lt;a href="https://blog.linguinecode.com/post/add-react-router-to-react" rel="noopener noreferrer"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So your cat app is growing and you want to make it easier for your users to digest the content.&lt;/p&gt;

&lt;p&gt;Great! Let’s add React Router DOM to your React cat application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is React Router DOM
&lt;/h2&gt;

&lt;p&gt;React Router DOM is a React library for the web. It utilizes another core library called React Router.&lt;/p&gt;

&lt;p&gt;It’s main purpose is to allow the engineer to create routes for a React single page application.&lt;/p&gt;

&lt;p&gt;Simple enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  The React Router goal
&lt;/h2&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F29152336%2Fcat-app-with-react-router.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F29152336%2Fcat-app-with-react-router.jpg" alt="Cat React app diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The goal for this tutorial is to build a cat application that has 3 different routes.&lt;/p&gt;

&lt;p&gt;The first route is going to be the home page, that displays the list of cat names.&lt;/p&gt;

&lt;p&gt;And each cat item is a link that takes the user to that cat item unique URL route.&lt;/p&gt;

&lt;p&gt;2 pages so far.&lt;/p&gt;

&lt;p&gt;The third page is going to be the, add a cat page. It’s a simple form that allows your add a new cat.&lt;/p&gt;

&lt;p&gt;I’ll also be using the new React hook API, so if you’re not familiar with it, please read a previous article on it. &lt;a href="https://blog.linguinecode.com/post/getting-started-with-react-hooks" rel="noopener noreferrer"&gt;Intro to React hooks&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing React dependencies
&lt;/h2&gt;

&lt;p&gt;In the terminal, I’m going to run this command:&lt;/p&gt;

&lt;p&gt;npm install –save react react-dom react-router-dom react-scripts&lt;/p&gt;

&lt;p&gt;We’re going to install React, React Router DOM, and React Scripts.&lt;/p&gt;

&lt;p&gt;React Scripts is the command tool that is used for Create React App. It will helps us develop faster.&lt;/p&gt;

&lt;p&gt;You’re package.json file should look like similar to 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F25120447%2Freact-router-package-json-file.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F25120447%2Freact-router-package-json-file.png" alt="React router package json file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The project structure
&lt;/h2&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F29152446%2Freact-router-app-structure.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F29152446%2Freact-router-app-structure.jpg" alt="React router app structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The project structure is going to be fairly simple.&lt;/p&gt;

&lt;p&gt;In the root of the project I’m going to have a public, and src directory.&lt;/p&gt;

&lt;p&gt;The public directory holds our index.html skeleton framework.&lt;/p&gt;

&lt;p&gt;The src directory will hold the React code.&lt;/p&gt;

&lt;p&gt;Inside the src directory I’ve added another directory called pages.&lt;/p&gt;

&lt;p&gt;pages will hold 3 React JavaScript files.&lt;/p&gt;

&lt;p&gt;One to add a new cat, another to view a list of all the cats, and the last one to view a specific cat.&lt;/p&gt;

&lt;p&gt;We also have the routes.js file. This file is a configuration file that will be an array of React routes.&lt;/p&gt;

&lt;p&gt;Each object inside the routes array will contain data such as path value of the page, and what page React component to render when the URL path matches.&lt;/p&gt;

&lt;p&gt;And of course, the App.js, this file will glue everything together and be the main file that holds the app logic, and state data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the list of cats view
&lt;/h2&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F29152548%2Fcat-list-loop.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F29152548%2Fcat-list-loop.jpg" alt="react render loop concept"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;em&gt;CatList.js&lt;/em&gt; file I added the following code.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28021417%2Freact-router-with-link-1024x925.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28021417%2Freact-router-with-link-1024x925.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this file I’m importing a React Component called Link from the React Router DOM node module.&lt;/p&gt;

&lt;p&gt;The Link component allows us to wrap an HTML element or a React component to act as link, and it helps users navigate through the React routes.&lt;/p&gt;

&lt;p&gt;Now, the CatList component accepts a prop called cats.&lt;/p&gt;

&lt;p&gt;The React prop &lt;em&gt;cats&lt;/em&gt; needs to be an array of objects which gets loop through the array &lt;strong&gt;map&lt;/strong&gt; function, and outputs list items that links to the interior view of a cat.  &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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28164503%2Fcat-list-react-output.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28164503%2Fcat-list-react-output.jpg" alt="Cat list react output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the React form
&lt;/h2&gt;

&lt;p&gt;Before I get started creating the single view for a cat. I need to be able to populate the list of cats.&lt;/p&gt;

&lt;p&gt;This app will require a React form that allows some user input.&lt;/p&gt;

&lt;p&gt;This React form will also be it’s own React route.&lt;/p&gt;

&lt;p&gt;The code will live in a file called AddCat.js.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28165424%2Freact-form-add-cat-853x1024.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28165424%2Freact-form-add-cat-853x1024.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There’s a lot to digest here, so I will break it down.&lt;/p&gt;

&lt;p&gt;In line 5, I’ve created a function called generateCat that chooses a random cat image that I have in my project, and generates the URL source for that image.&lt;/p&gt;

&lt;p&gt;In line 12, I’m using the React hook, useState, to keep track of the new cats’ name.&lt;/p&gt;

&lt;p&gt;And I’m changing the value of the cats’ name inside a onChange event in the input HTML element.&lt;/p&gt;

&lt;p&gt;Now, when the user is ready to submit the new cat, they will click on the submit button.&lt;/p&gt;

&lt;p&gt;The submit button has a onClick event that checks for a couple conditions.&lt;/p&gt;

&lt;p&gt;One, it checks if the a custom property, onSubmit, has been provided by the parent React Component.&lt;/p&gt;

&lt;p&gt;It then checks if the user has even entered a cat name.&lt;/p&gt;

&lt;p&gt;If those 2 conditions pass, then it passes down some cat information to the React parent component such as the cat name, a slug, and the random cat picture that was generated.&lt;/p&gt;

&lt;p&gt;Which in this case, the parent React component is in the App.js file.&lt;/p&gt;

&lt;p&gt;As for the slug, it’s using a custom helper function that turns a name to a url endpoint.&lt;/p&gt;

&lt;p&gt;It strips the white space, and any other special characters that don’t belong in the url.&lt;/p&gt;

&lt;p&gt;For example, it will convert the name, “Mr. Frizzle” to “mr-frizzle”.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28171035%2Freact-form-add-cat.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28171035%2Freact-form-add-cat.jpg" alt="React form view"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the single view
&lt;/h2&gt;

&lt;p&gt;Since we know what the data is going to look like from the form above, than we can start making assumptions how to filter and find the right cat for the single view.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28171641%2Fsingle-cat-view-921x1024.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28171641%2Fsingle-cat-view-921x1024.png" alt="Getting access to history object with React router dom withRouter"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On line 2, I’m importing a HOC (higher order component) from React Router DOM called withRouter, and I’m wrapping it around the SingleCat component.&lt;/p&gt;

&lt;p&gt;withRouter lets a React component to have access to the history, location, and match object.&lt;/p&gt;

&lt;p&gt;This is important because this React component needs access so it may attempt to get the unique cat slug in the URL, and find the object in the cat list that contains that unique slug.&lt;/p&gt;

&lt;p&gt;In line 5, I’m initiating another useState hook, and a useEffect hook.&lt;/p&gt;

&lt;p&gt;When the component mounts, the code will grab a parameter called &lt;strong&gt;name&lt;/strong&gt; aka the slug.&lt;/p&gt;

&lt;p&gt;It will then run an array filter method to look for the cat object that contains that slug value.&lt;/p&gt;

&lt;p&gt;If the filter method returns an empty array then it will send the user back to the home page.&lt;/p&gt;

&lt;p&gt;And if the filter method does return an object, then it will trigger the useState hook to update the variable value of &lt;strong&gt;cat&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once the variable &lt;strong&gt;cat&lt;/strong&gt; has a value, we will render out the data of the cat.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28182804%2Fmr-frizzle-output.jpg" 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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28182804%2Fmr-frizzle-output.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating React Router config file
&lt;/h2&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28182350%2Freact-router-config-file.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28182350%2Freact-router-config-file.png" alt="React router config file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This config lives in the route.js file.&lt;/p&gt;

&lt;p&gt;The only purpose of this file is to import all the pages, and assign them a path value for the React route component that I’m about to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gluing React with its routes
&lt;/h2&gt;

&lt;p&gt;Now for the file that glues everything together, App.js.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28183009%2Freact-router-route-components-553x1024.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F28183009%2Freact-router-route-components-553x1024.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don’t let all the HTML markup scare you. The job for this file is really simple.&lt;/p&gt;

&lt;p&gt;If you take a look at the top, you’ll see that I’m importing a few React components from the React Router DOM library.&lt;/p&gt;

&lt;p&gt;The first import is the BrowserRouter component, that gets used in line 16.&lt;/p&gt;

&lt;p&gt;BrowserRouter uses the HTML 5 history API, and must be used before adding any routes.&lt;/p&gt;

&lt;p&gt;The next component, and probably the most important one, is the Route component.&lt;/p&gt;

&lt;p&gt;The Route component is responsible to display the React component assigned to it, only when the location (url) matches.&lt;/p&gt;

&lt;p&gt;You can see me using the Route component in line 30 as I’m looping through the route configuration that were created previously.&lt;/p&gt;

&lt;p&gt;The Route component accepts a property called &lt;em&gt;path&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This property accepts a regular string or a regex expression as a path. The path property does not need to be provided also.&lt;/p&gt;

&lt;p&gt;If a Route component is not given a path value, then the component attached to it will always be shown.&lt;/p&gt;

&lt;p&gt;So it’s highly recommended that you add a path value.&lt;/p&gt;

&lt;p&gt;In line 34, I’m attaching the React component that is defined in the route configuration file, and I’m tossing a couple custom properties for the list page, and the add a cat page.&lt;/p&gt;

&lt;p&gt;In line 10, I’ve also created another state property called &lt;strong&gt;cats&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That variable is responsible for tracking and holding all the cats that a user has added.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As your application grows, it will require routes and pages views to be created.&lt;/p&gt;

&lt;p&gt;React Router DOM, allows you to create routes really easily, and provides other helper functions and tools to allow users to navigate through your React app.&lt;/p&gt;

&lt;p&gt;Github source: &lt;a href="https://github.com/rleija703/react-examples/tree/master/examples/with-router" rel="noopener noreferrer"&gt;with-router&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>7 Webpack plugins for your next React app</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Fri, 26 Apr 2019 13:11:23 +0000</pubDate>
      <link>https://forem.com/rleija_/7-webpack-plugins-for-your-next-react-app-133p</link>
      <guid>https://forem.com/rleija_/7-webpack-plugins-for-your-next-react-app-133p</guid>
      <description>&lt;p&gt;&lt;em&gt;original post @ &lt;a href="https://linguinecode.com/post/top-webpack-plugins" rel="noopener noreferrer"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpack optimization
&lt;/h2&gt;

&lt;p&gt;Webpack comes with a configuration property called &lt;strong&gt;optimization&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Inside &lt;strong&gt;optimization&lt;/strong&gt; another property named &lt;strong&gt;minimize&lt;/strong&gt;, and &lt;strong&gt;minimizer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;minimize&lt;/strong&gt; equals true, then everything inside &lt;strong&gt;minimizer&lt;/strong&gt; will trigger.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18191438%2Fwebpack-optimization-prop.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18191438%2Fwebpack-optimization-prop.png" alt="Webpack optimize property"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next couple of Webpack plugins that I will cover, they should be inside the &lt;strong&gt;minimizer&lt;/strong&gt; property.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Terser webpack plugin&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The Terser plugin is a great tool to minimize the application JavaScript bundle file for production.&lt;/p&gt;

&lt;p&gt;Another plus to this plugin is that it supports ES6+.&lt;/p&gt;

&lt;p&gt;Here is a basic configuration for Terser.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18191112%2Fwebpack-terser-example-1024x1021.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18191112%2Fwebpack-terser-example-1024x1021.png" alt="Terser webpack plugin basic configuration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://webpack.js.org/plugins/terser-webpack-plugin/" rel="noopener noreferrer"&gt;Terser plugin&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Optimize CSS assets Webpack plugin&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The Optimize CSS assets Webpack plugin is another one for production build.&lt;/p&gt;

&lt;p&gt;It helps optimize and minimize your React CSS code.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18192425%2Foptimize-css-assets-webpack-plugin-1024x509.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18192425%2Foptimize-css-assets-webpack-plugin-1024x509.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://github.com/NMFR/optimize-css-assets-webpack-plugin" rel="noopener noreferrer"&gt;Optimize css assets plugin&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpack plugins
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;HTML Webpack plugin&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The HTML Webpack plugin is a handy plugin for both development and production build.&lt;/p&gt;

&lt;p&gt;It tells Webpack to generate an HTML file and inject a script tag with the JavaScript code.&lt;/p&gt;

&lt;p&gt;All you need to do is supply the HTML template to use.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18192942%2Fhtml-webpack-plugin-configuration.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F18192942%2Fhtml-webpack-plugin-configuration.png" alt="HTML webpack plugin basic configuration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may also add minification rules such as removing comments, minifying the CSS, and JavaScript.&lt;/p&gt;

&lt;p&gt;But if you’d like to only use the minify property for build you can do something like.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23142733%2Fwebpack-html-plugin-prod1-780x1024.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23142733%2Fwebpack-html-plugin-prod1-780x1024.png" alt="Mnify HTML webpack plugin only for production"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://github.com/jantimon/html-webpack-plugin" rel="noopener noreferrer"&gt;HTML Webpack plugin&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Webpack Define plugin&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This plugin comes with the Webpack node module, and it’s a handy little tool when developing your React application.&lt;/p&gt;

&lt;p&gt;The DefinePlugin allows you to create environment variables and makes it accessible to your JavaScript code.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23141654%2Fwebpack-define-plugin-1024x440.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23141654%2Fwebpack-define-plugin-1024x440.png" alt="Webpack DefinePlugin basic use"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://webpack.js.org/plugins/define-plugin/" rel="noopener noreferrer"&gt;Webpack DefinePlugin&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mini CSS Extract plugin
&lt;/h3&gt;

&lt;p&gt;This plugin is another great production tool.&lt;/p&gt;

&lt;p&gt;It allows your to extract the CSS in your React app into separate files per JavaScript file.&lt;/p&gt;

&lt;p&gt;Some other features that are enjoyable versus the Extract Text Webpack plugin is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Async loading&lt;/li&gt;
&lt;li&gt;  No duplicate compilation&lt;/li&gt;
&lt;li&gt;  Easier to use&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23143456%2Fmini-css-extract-config-1024x393.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23143456%2Fmini-css-extract-config-1024x393.png" alt="Mini CSS extract plugin webpack configuration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpack modules
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Babel loader&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This plugin allows you to write the latest generation of JavaScript and converts it to a compiled ES5 version.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23161010%2Fbabel-example.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23161010%2Fbabel-example.png" alt="Babel ES6 feature to transpiled version"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to configure babel-loader for .js, .jsx, and as well for Typescript (if you’re using it).&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23161503%2Fbabel-loader-config.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23161503%2Fbabel-loader-config.png" alt="Webpack babel loader configration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://github.com/babel/babel-loader" rel="noopener noreferrer"&gt;Babel loader&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Babel preset react app&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This module is maintained by the Create React App team and it has a great set of presets for your React App.&lt;/p&gt;

&lt;p&gt;All we need to do is add more to the babel loader configuration.&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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23162057%2Fbabel-loader-config-with-react-presets-1024x490.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%2Fdaqxzxzy8xq3u.cloudfront.net%2Fwp-content%2Fuploads%2F2019%2F04%2F23162057%2Fbabel-loader-config-with-react-presets-1024x490.png" alt="Babel loader configuration with react presets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://www.npmjs.com/package/babel-preset-react-app" rel="noopener noreferrer"&gt;Babel preset react app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webpack</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Simple guide to setup Redux to a React app</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Mon, 22 Apr 2019 12:24:39 +0000</pubDate>
      <link>https://forem.com/rleija_/simple-guide-to-setup-redux-to-a-react-apphttps-dev-to-new-4fj</link>
      <guid>https://forem.com/rleija_/simple-guide-to-setup-redux-to-a-react-apphttps-dev-to-new-4fj</guid>
      <description>&lt;p&gt;&lt;em&gt;original post @ &lt;a href="https://blog.linguinecode.com/post/setup-redux-react"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In a previous article I wrote about &lt;a href="https://blog.linguinecode.com/post/master-react-state-and-props"&gt;how to use React state&lt;/a&gt; by building a simple cat application.&lt;/p&gt;

&lt;p&gt;When the application is small its relatively easy to maintain React state.&lt;/p&gt;

&lt;p&gt;But as the application grows the React state tree gets messier, unmanageable, and more complicated.&lt;/p&gt;

&lt;p&gt;And this even more true when your app state starts to hold server responses, cache and UI state data.&lt;/p&gt;

&lt;p&gt;UI state data may include routes information, whether to show a loading spinner, pagination, tabs, etc.&lt;/p&gt;

&lt;p&gt;At some point your app will have so much going on that you’ve lost control over your app state, and how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Redux is here to solve these problems
&lt;/h2&gt;

&lt;p&gt;Redux is a tiny state management library.&lt;/p&gt;

&lt;p&gt;It’s meant to make your state management more predictable, and centralize your React state data, and state logic.&lt;/p&gt;

&lt;p&gt;Redux solves these problems by implementing 3 core principals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Principal 1: Single source of truth
&lt;/h3&gt;

&lt;p&gt;Your entire app state data is in one object tree.&lt;/p&gt;

&lt;p&gt;This tree may also be known as a store.&lt;/p&gt;

&lt;p&gt;By maintaining a single store it allows you to be debug or inspect your application much easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Principal 2: State is read-only
&lt;/h3&gt;

&lt;p&gt;Your store data gets passed down as React props. Which React doesn’t allow you to modify the props object directly.&lt;/p&gt;

&lt;p&gt;This will help keep consistency through out the app.&lt;/p&gt;

&lt;p&gt;Redux only allows you to update your store data through a functions called dispatch which you must defined the &lt;strong&gt;action&lt;/strong&gt; to trigger.&lt;/p&gt;

&lt;p&gt;These &lt;strong&gt;actions&lt;/strong&gt;, describe what will be changing or happening to the store.&lt;/p&gt;

&lt;h3&gt;
  
  
  Principal 3: Changes are made with pure functions
&lt;/h3&gt;

&lt;p&gt;These function are also known as &lt;strong&gt;reducers&lt;/strong&gt;, which are attached to an &lt;strong&gt;action&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The job of a reducer is to get the current state and an action and return the next state.&lt;/p&gt;

&lt;p&gt;So when you make a call to an action such as, &lt;em&gt;ADD_CAT&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Redux will take that action request, check if it exists and if it has a &lt;strong&gt;reducer&lt;/strong&gt; attached to it.&lt;/p&gt;

&lt;p&gt;It will then execute that &lt;strong&gt;reducer&lt;/strong&gt; function to update the store data.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. Redux doesn’t just run on React, it may be used on any view JavaScript library, and even vanilla JS as well!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Redux to React
&lt;/h2&gt;

&lt;p&gt;For the sake of simplicity, I’m going to modify the cat list application that was built previously to showcase how to use Redux in React.&lt;/p&gt;

&lt;p&gt;I know it’s another list app, but it’s simple and it’s easy to follow.&lt;/p&gt;

&lt;p&gt;Also if you’d like to follow along with the actual code, scroll to the bottom for the Github source link.&lt;/p&gt;

&lt;p&gt;The first step I need to take is to create the &lt;strong&gt;package.json&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PJyqPzoZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/19041952/redux-package-json-file-701x1024.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PJyqPzoZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/19041952/redux-package-json-file-701x1024.png" alt="React Redux package json file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This project is going to require the following React libraries&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React&lt;/strong&gt; – The UI library.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React DOM&lt;/strong&gt; – The tool that let’s us attache our React app to the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redux&lt;/strong&gt; – The state management library.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Redux&lt;/strong&gt; – The Redux React library that let’s us attach the Redux store to the React application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redux Thunk&lt;/strong&gt; – This library is a bit of an overkill for this example but it’s popular, and wanted to demonstrate some of it’s pros.&lt;/p&gt;

&lt;p&gt;Redux Thunk let’s us split our &lt;strong&gt;reducers&lt;/strong&gt; in smaller pieces when the application grows to enormous, and it let’s us run &lt;strong&gt;dispatch&lt;/strong&gt; inside our actions.&lt;/p&gt;

&lt;p&gt;Once your &lt;strong&gt;package.json&lt;/strong&gt; file is ready, run &lt;em&gt;npm install&lt;/em&gt; inside your terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  The React app structure
&lt;/h2&gt;

&lt;p&gt;Here is the structure of the application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0kxZvyWZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/19114936/with-redux-app-structure.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0kxZvyWZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/19114936/with-redux-app-structure.jpg" alt="React redux app structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you may see, I have my &lt;strong&gt;public&lt;/strong&gt; directory that holds the initial &lt;strong&gt;index.html&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;I also have a &lt;strong&gt;src&lt;/strong&gt; directory that holds a few important files for this application to work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.js&lt;/strong&gt; – It’s responsible for making Redux available in the React application, as well as grabbing the React application and dumping it onto the HTML.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;App.js&lt;/strong&gt; – The main source application file. It allows you add cat names, and display them in a list format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;store.js&lt;/strong&gt; – Is the glue that grabs the reducers and creates a Redux store out of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;reducers/cats.js&lt;/strong&gt; – Responsible for describing what the cat reducer looks like, naming the action, and attaching the action to a function that modifies the cat reducer data.&lt;/p&gt;

&lt;p&gt;Now that you know the app structure, let’s start going through the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Redux reducer
&lt;/h3&gt;

&lt;p&gt;First I’ll build my cat reducer file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iyiZUe3---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/19041539/redux-store-example.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iyiZUe3---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/19041539/redux-store-example.png" alt="Redux store reducer example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first thing thing I will create is a variable named &lt;strong&gt;initialState&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;initialState&lt;/strong&gt; will hold a property named &lt;strong&gt;list&lt;/strong&gt;, which is an array of cat names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;initialState&lt;/strong&gt; also defines what the initial state looks like for the cat state.&lt;/p&gt;

&lt;p&gt;The next variable to create is called &lt;strong&gt;actions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;actions&lt;/strong&gt; is a key value pair object.&lt;/p&gt;

&lt;p&gt;The key is the name of the action and the value is the reducer to be executed.&lt;/p&gt;

&lt;p&gt;Right below the &lt;strong&gt;actions&lt;/strong&gt; variable, I defined a simple function called &lt;strong&gt;addCat&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The name is pretty self explanatory. The function adds the cat name onto the &lt;strong&gt;list&lt;/strong&gt; property in the state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Redux store file
&lt;/h2&gt;

&lt;p&gt;This file may look scary but it’s not that bad. I’ll go over it step by step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ubFAOiMu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20043703/redux-store-file-1024x724.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ubFAOiMu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20043703/redux-store-file-1024x724.png" alt="Redux create store file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, I’m importing Redux libraries, and also the cat reducer file that was created above.&lt;/p&gt;

&lt;p&gt;Second, I’m creating a function called &lt;strong&gt;createReducer&lt;/strong&gt;, that glues together the initial state, and the actions, thus creating a reducer.&lt;/p&gt;

&lt;p&gt;I used it to create my cat reducer, and then inject into a variable called*&lt;em&gt;rootReducer&lt;/em&gt;*.&lt;/p&gt;

&lt;p&gt;I then export a new store by using the create store function and supplying it the root reducer with some middleware.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;combineReducers&lt;/strong&gt; may be another overkill in this app example but it shows you how to split and add reducers to your Redux store.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the cat name list app
&lt;/h2&gt;

&lt;p&gt;The next file to work on is the &lt;strong&gt;App.js&lt;/strong&gt; file. This file will be responsible to display the UI, allow the user to enter a new cat name, and add it to the Redux store.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uWUb-OES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20044552/redux-app-file-655x1024.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uWUb-OES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20044552/redux-app-file-655x1024.png" alt="Using Redux connect in React component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re not familiar with React hooks, I highly recommend you read this article that teaches you how they work and how they’re used: &lt;a href="https://blog.linguinecode.com/post/getting-started-with-react-hooks"&gt;React useState&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Moving on, this file is huge. Step by step time again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rG3Q6x63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20045830/react-redux-breakdown-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rG3Q6x63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20045830/react-redux-breakdown-1.png" alt="Using React redux connect to get state data"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step here is to import React &lt;strong&gt;useState&lt;/strong&gt;, and the &lt;strong&gt;connect&lt;/strong&gt; function from React Redux library.&lt;/p&gt;

&lt;p&gt;Then I’ll create the React component called &lt;strong&gt;App&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I’m then exporting the &lt;strong&gt;App&lt;/strong&gt; React component inside the &lt;strong&gt;connect&lt;/strong&gt; function as a HOC (higher order component).&lt;/p&gt;

&lt;p&gt;You might be asking, “what does connect do?”&lt;/p&gt;

&lt;p&gt;Good question, the &lt;strong&gt;connect&lt;/strong&gt; function let’s a React component latch itself onto the Redux store.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;connect&lt;/strong&gt; function does not modify the component, but it creates a new component around to pass any state data from the Redux store, and it provides a function called &lt;strong&gt;dispatch&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a kid illustration to visually see how it works.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LQUxy_nU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20142206/kid-illustration-redux-connect-1024x576.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LQUxy_nU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20142206/kid-illustration-redux-connect-1024x576.jpg" alt="How Redux connect wraps React component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Redux &lt;strong&gt;connect&lt;/strong&gt; accepts a handful of parameters but I’ll go over the 2 most important ones.&lt;/p&gt;

&lt;p&gt;In the example above I’m passing in only the first parameter which Redux calls, &lt;strong&gt;mapStateToProps&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;mapStateToProps&lt;/strong&gt; is a function that allows you to pick and choose what Redux store data you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fa8M7dpB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20143605/redux-map-state-to-props-example-1024x390.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fa8M7dpB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20143605/redux-map-state-to-props-example-1024x390.png" alt="mapStateToprops variable inside Redux connect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;App.js&lt;/strong&gt; file, I decided to get all, but you don’t have to.&lt;/p&gt;

&lt;p&gt;If the first parameter is provided, then the wrapper component will subscribe to the Redux store.&lt;/p&gt;

&lt;p&gt;It acts like a listener to always provide the latest data to the component you’ve created.&lt;/p&gt;

&lt;p&gt;If you’d like your app to not subscribe to the store just pass &lt;strong&gt;null&lt;/strong&gt; or &lt;strong&gt;undefined&lt;/strong&gt; as the first parameter.&lt;/p&gt;

&lt;p&gt;The second parameter in Redux connect is &lt;strong&gt;mapDispatchToProps&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;mapDispatchToProps&lt;/strong&gt; allows you to create custom dispatch functions and pass them to the React component.&lt;/p&gt;

&lt;p&gt;Let’s take a look at the input and button section of the React component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B9ECVugP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20144328/redux-dispatch-onclick-798x1024.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B9ECVugP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20144328/redux-dispatch-onclick-798x1024.png" alt="Using setState onChange and Redux dispatch onClick"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the React component and before the &lt;strong&gt;return&lt;/strong&gt; statement, I’ve create a new &lt;strong&gt;useState&lt;/strong&gt; hook for the cat name.&lt;/p&gt;

&lt;p&gt;I’ve also attached &lt;strong&gt;setCatName&lt;/strong&gt; inside the input HTML element for the &lt;strong&gt;onChange&lt;/strong&gt; event.&lt;/p&gt;

&lt;p&gt;So whenever a user is typing the new cat name, &lt;strong&gt;setCatName&lt;/strong&gt; will trigger, and update the value of &lt;strong&gt;catName&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I’ve also added a button to submit the new cat name on the &lt;strong&gt;onClick&lt;/strong&gt; event.&lt;/p&gt;

&lt;p&gt;Inside the &lt;strong&gt;onClick&lt;/strong&gt; event, I’m saying to check if the cat name is empty or not. If it is empty return an &lt;strong&gt;alert&lt;/strong&gt; saying “Cat name cannot be empty!”&lt;/p&gt;

&lt;p&gt;If there is a name, I want to trigger the &lt;em&gt;ADD_CAT&lt;/em&gt; Redux action by using &lt;strong&gt;dispatch&lt;/strong&gt;, and supply the new cat name value in a property called &lt;strong&gt;payload&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;payload&lt;/strong&gt; is a common practice when passing data through dispatch.&lt;/p&gt;

&lt;p&gt;It doesn’t have to be called payload, you can call it whatever you want. But the property &lt;strong&gt;type&lt;/strong&gt;, must exist.&lt;/p&gt;

&lt;p&gt;Right after the &lt;strong&gt;dispatch&lt;/strong&gt; function, I’m resetting the cat name value to an empty string.&lt;/p&gt;

&lt;p&gt;What does &lt;strong&gt;dispatch&lt;/strong&gt; do again??&lt;/p&gt;

&lt;p&gt;Yes, &lt;strong&gt;dispatch&lt;/strong&gt; is a function that you only get from Redux &lt;strong&gt;connect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Dispatch allows you trigger actions defined in your reducer files, and it’s the only way to modify the Redux store.&lt;/p&gt;

&lt;p&gt;Think of dispatch as the &lt;strong&gt;setState&lt;/strong&gt; of Redux.&lt;/p&gt;

&lt;p&gt;The final part to go over in the &lt;strong&gt;App.js&lt;/strong&gt; file is displaying the cat names that I’ve fetch from my Redux store.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z9ewAO0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20145641/looping-through-list-react.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z9ewAO0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20145641/looping-through-list-react.png" alt="React loop inside render"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Redux store provider component
&lt;/h2&gt;

&lt;p&gt;Finally, the final part to this masterpiece.&lt;/p&gt;

&lt;p&gt;In our &lt;strong&gt;index.js&lt;/strong&gt; file I’m going to add the Provider component to the React application, and supply the created store from the &lt;strong&gt;store.js&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZTXNeADe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20150005/redux-provider-store.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZTXNeADe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://daqxzxzy8xq3u.cloudfront.net/wp-content/uploads/2019/04/20150005/redux-provider-store.png" alt="Adding redux store provider component to React"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Provider component makes the Redux store available to any nested components that have been wrapped in the &lt;strong&gt;connect&lt;/strong&gt; function.&lt;/p&gt;

&lt;p&gt;It’s good practice to make your Provider at the top level, that way your entire React application has access to the Redux store data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Redux has a lot of boilerplate and moving parts, but once you start understanding it; it just makes more sense on how this state management tool helps manage large projects.&lt;/p&gt;

&lt;p&gt;If you have any questions feel free to ask me on &lt;a href="https://twitter.com/rleija_"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rleija703/react-examples/tree/master/examples/with-redux"&gt;Github Source Link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>My work setup, what's yours?</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Fri, 05 Apr 2019 12:45:11 +0000</pubDate>
      <link>https://forem.com/rleija_/my-work-setup-what-s-yours-54e2</link>
      <guid>https://forem.com/rleija_/my-work-setup-what-s-yours-54e2</guid>
      <description>&lt;p&gt;I feel like you can tell a lot about a person from there desk setup.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fworkstation-1.jpg" 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fworkstation-1.jpg"&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fworkstation-2.jpg" 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fworkstation-2.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I love soccer&lt;/li&gt;
&lt;li&gt;I like coffee&lt;/li&gt;
&lt;li&gt;My keyboard says gamer but my mouse says productivity??&lt;/li&gt;
&lt;li&gt;I'm religious (that's as far as I'll get into that)&lt;/li&gt;
&lt;li&gt;Water is a must&lt;/li&gt;
&lt;li&gt;I like photography&lt;/li&gt;
&lt;li&gt;I use Twitter a lot. A little bit too much.&lt;/li&gt;
&lt;li&gt;Rosetta Stone squishy ball for a bit of distraction&lt;/li&gt;
&lt;li&gt;I'm both a Windows and a Mac user.&lt;/li&gt;
&lt;li&gt;I'm somewhat scattered in my brain&lt;/li&gt;
&lt;li&gt;I'm on dev.to so that must mean I'm somewhat of a code nerd :)&lt;/li&gt;
&lt;li&gt;I have an air freshener on the right side, so I like a good smelling area&lt;/li&gt;
&lt;li&gt;I have gum, so good breath is a must&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That was fun, what's your desk setup say about you?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>discuss</category>
      <category>showdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>8 easy steps to add Okta authentication to your React app</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Thu, 04 Apr 2019 15:18:20 +0000</pubDate>
      <link>https://forem.com/rleija_/8-easy-steps-to-add-okta-authentication-to-your-react-app-58b7</link>
      <guid>https://forem.com/rleija_/8-easy-steps-to-add-okta-authentication-to-your-react-app-58b7</guid>
      <description>&lt;p&gt;&lt;em&gt;original post @ &lt;a href="https://linguinecode.com/post/add-okta-authentication-to-react-app"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Okta has been growing over 45% year over year since 2017, and it doesn't seem to be slowing down.&lt;/p&gt;

&lt;p&gt;Big and small companies are using Okta for their external and internal software tools.&lt;/p&gt;

&lt;p&gt;Okta is a user authentication management tool that helps businesses manage their employees software accounts with their company software tools.&lt;/p&gt;

&lt;p&gt;For example, let's say I own a cat store and I use Slack, Jira, and Github.&lt;/p&gt;

&lt;p&gt;If I hire an engineer, I'll have to create multiple accounts for that specific engineer.&lt;/p&gt;

&lt;p&gt;And if that engineer leaves, I'll have to go through each tool and remove that person account. This is a problem.&lt;/p&gt;

&lt;p&gt;Instead of doing all that manual work, you can integrate all those software tools to an Okta account and assign an Okta user to a software tool.&lt;/p&gt;

&lt;p&gt;That means you can create 1 Okta user to your Okta account, and Okta will handle adding and removing an account for all your software tools that you've integrated with.&lt;/p&gt;

&lt;p&gt;The neat part about Okta is that you can implement it to your own internal applications.&lt;/p&gt;

&lt;p&gt;In this article I'll go over 8 easy steps to adding Okta authentication to your React application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Create Okta account
&lt;/h2&gt;

&lt;p&gt;First step is to head over to the &lt;a href="http://okta.com"&gt;okta.com&lt;/a&gt; and create an account.&lt;/p&gt;

&lt;p&gt;You can create a free 30 day trial account to test on. But if you have one already go to step 2.&lt;/p&gt;

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




&lt;p&gt;That’s pretty easy.&lt;/p&gt;

&lt;p&gt;You will than receive an email with your log in credentials, and a link to the log in page.&lt;/p&gt;

&lt;p&gt;Go ahead and log in, and set your new password.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create an Okta app
&lt;/h2&gt;

&lt;p&gt;Once you’re logged in, you’ll need to head over to the application page.&lt;/p&gt;

&lt;p&gt;You can find that under the Application menu tab when you hover over it.&lt;/p&gt;

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

&lt;p&gt;There is also a shortcut link to add a new application on the right side.&lt;/p&gt;

&lt;p&gt;But if you’re in the application page then click &lt;strong&gt;Add Application&lt;/strong&gt; next.&lt;/p&gt;

&lt;p&gt;Then click on &lt;strong&gt;Create New App&lt;/strong&gt;. It should be a green button on the left hand side.&lt;/p&gt;

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

&lt;p&gt;A popup will be presented, and you’ll need to add the following configuration to fit your React application.&lt;/p&gt;

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

&lt;p&gt;You will than be prompted to add some basic setting configuration about your app.&lt;/p&gt;

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

&lt;p&gt;For the moment you can add your current localhost and port number for for your test app.&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Save&lt;/strong&gt; once those are added.&lt;/p&gt;

&lt;p&gt;In the bottom page of your Okta app you’ll find your Client ID.&lt;/p&gt;

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

&lt;p&gt;Click on the right button to copy it to your clipboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Assign user to Okta app
&lt;/h2&gt;

&lt;p&gt;The next step is to assign a user to your Okta app.&lt;/p&gt;

&lt;p&gt;If a Okta user is not assigned to that app, they will get denied.&lt;/p&gt;

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

&lt;p&gt;That’s okay too if you want. But at least add yourself!&lt;/p&gt;

&lt;p&gt;Go back to the application page and click on the &lt;strong&gt;Assign Application&lt;/strong&gt; button.&lt;/p&gt;

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

&lt;p&gt;Select your application and the user you want to assign it too and click &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And click the confirmation button right after.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Add trusted origin to Okta
&lt;/h2&gt;

&lt;p&gt;The last configuration that you need to do in your Okta account is to add your trusted origins.&lt;/p&gt;

&lt;p&gt;This will make sure we can avoid any CORS issues.&lt;/p&gt;

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

&lt;p&gt;Hover over the &lt;strong&gt;Security&lt;/strong&gt; menu and select the &lt;strong&gt;API&lt;/strong&gt; sub menu item.&lt;/p&gt;

&lt;p&gt;The first tab you’ll see in the page is about tokens, but we want to change that to Trusted Origins tab.&lt;/p&gt;

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

&lt;p&gt;And select &lt;strong&gt;Add Origin&lt;/strong&gt; next.&lt;/p&gt;

&lt;p&gt;Add the following field values onto the form and click &lt;strong&gt;Save&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;The boring stuff has been completed. Now the coding begins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Create React app
&lt;/h2&gt;

&lt;p&gt;To keep this example guide simple I’m going to use Create React App tooling to help us get quicker to the important part of this guide.&lt;/p&gt;

&lt;p&gt;Let’s create a directory called &lt;strong&gt;okta-sample&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Inside our new directory, create a &lt;strong&gt;package.json&lt;/strong&gt; file and add the following.&lt;/p&gt;

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

&lt;p&gt;Now you may install those dependencies by running npm install.&lt;/p&gt;

&lt;p&gt;Let’s also create a directory called &lt;strong&gt;public&lt;/strong&gt; and &lt;strong&gt;src&lt;/strong&gt; in the root of the project.&lt;/p&gt;

&lt;p&gt;Inside the &lt;strong&gt;public&lt;/strong&gt; directory let’s add an &lt;strong&gt;index.html&lt;/strong&gt; file.&lt;/p&gt;

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

&lt;p&gt;The &lt;strong&gt;index.html&lt;/strong&gt; file will serve as a basic skeleton for the app.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;src&lt;/strong&gt; directory, all of your React code will live in there.&lt;/p&gt;

&lt;p&gt;Inside &lt;strong&gt;src&lt;/strong&gt;, create 2 files called &lt;strong&gt;index.js&lt;/strong&gt;, and &lt;strong&gt;App.js&lt;/strong&gt;. You’ll also need to add a &lt;strong&gt;pages&lt;/strong&gt; directory inside the &lt;strong&gt;src&lt;/strong&gt; directory.&lt;/p&gt;

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

&lt;p&gt;Go ahead and run npm start. It should boot up a browser window pointed to localhost:3000.&lt;/p&gt;

&lt;p&gt;And the web page should blank.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Create the index file
&lt;/h2&gt;

&lt;p&gt;In this file we’re doing a handful of actions here.&lt;/p&gt;

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

&lt;p&gt;We’re initializing the Browser router and adding Okta’s Security component.&lt;/p&gt;

&lt;p&gt;Which allows you to supply your Okta configurations to your React app.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. don’t hardcode production configurations like in this example.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;issuer&lt;/strong&gt; property is just the base URL to your Okta page. Don’t forget to add the slash &lt;strong&gt;/&lt;/strong&gt; in the end.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;redirect_uri&lt;/strong&gt;, and &lt;strong&gt;client_id&lt;/strong&gt; can be grabbed from the Okta application page.&lt;/p&gt;

&lt;p&gt;If you’re running your app locally during this step you might see your application broken.&lt;/p&gt;

&lt;p&gt;That’s because &lt;strong&gt;App.js&lt;/strong&gt; hasn’t been created or the routes. Let’s do that next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Create App.js file
&lt;/h2&gt;

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

&lt;p&gt;In this file you’ll see how will put the pieces together.&lt;/p&gt;

&lt;p&gt;The first step is to import React, React Router DOM modules called Route, and Link.&lt;/p&gt;

&lt;p&gt;Route is going to help us define public routes.&lt;/p&gt;

&lt;p&gt;And we’re going to use Link to help us build an easy 2 menu item navigation.&lt;/p&gt;

&lt;p&gt;The first link will be pointing to the home page page which is the log in page.&lt;/p&gt;

&lt;p&gt;The second link will help you go to the admin dashboard page.&lt;/p&gt;

&lt;p&gt;The other important part to this file is the SecureRoute component that is provided by Okta.&lt;/p&gt;

&lt;p&gt;This component helps you do the logic whether the user is allowed to enter the pag. This is determined if the user is authenticated or not.&lt;/p&gt;

&lt;p&gt;The last important piece to this file is the ImplicitCallback Okta React component.&lt;/p&gt;

&lt;p&gt;This component helps handle the response after Okta tells React if the user has successfully signed in or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Creating the admin dashboard &amp;amp; login page
&lt;/h2&gt;

&lt;p&gt;The admin dashboard will be a file in the pages directory called &lt;strong&gt;AdminDashboard.js&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;It’s a very simple and plain functional React component.&lt;/p&gt;

&lt;p&gt;The next file to create is for our home page. Which will display a sign in button.&lt;/p&gt;

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

&lt;p&gt;In the login importing Okta’s HOC(higher order component) called withAuth.&lt;/p&gt;

&lt;p&gt;And I’m wrapping it around the React class component LoginPage.&lt;/p&gt;

&lt;p&gt;This will be needed because withAuth provides a&lt;/p&gt;

&lt;p&gt;withAuth provides new property to the React component called user &lt;strong&gt;auth&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the example above you can see that I’m using a method called login inside a onClick event for the button.&lt;/p&gt;

&lt;p&gt;Inside the componentDidMount lifecycle you can see that I’m testing some of the other functionality that comes with withAuth such as checking if the user is authenticated, and getting the user information.&lt;/p&gt;

&lt;p&gt;withAuth also provides other functionality such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  getIdToken&lt;/li&gt;
&lt;li&gt;  logout&lt;/li&gt;
&lt;li&gt;  getAccessToken&lt;/li&gt;
&lt;li&gt;  handleAuthentication&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations you’ve added Okta authentication to your React application!&lt;/p&gt;

&lt;p&gt;Here’s the link to the source code. And if you found it interesting and helpful please give it a start!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rleija703/react-examples/tree/master/examples/with-okta"&gt;Github source link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to replicate a React component lifecycle with useEffect</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Thu, 28 Mar 2019 12:18:43 +0000</pubDate>
      <link>https://forem.com/rleija_/how-to-replicate-a-react-component-lifecycle-with-useeffect-5da5</link>
      <guid>https://forem.com/rleija_/how-to-replicate-a-react-component-lifecycle-with-useeffect-5da5</guid>
      <description>&lt;p&gt;This article has been moved to &lt;a href="https://blog.linguinecode.com/post/getting-started-with-react-useeffect"&gt;Linguine Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>5 reasons to go with CSS in JS for your next application</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Tue, 19 Mar 2019 13:31:04 +0000</pubDate>
      <link>https://forem.com/rleija_/5-reasons-to-go-with-css-in-js-for-your-next-application-43m</link>
      <guid>https://forem.com/rleija_/5-reasons-to-go-with-css-in-js-for-your-next-application-43m</guid>
      <description>&lt;p&gt;&lt;em&gt;original post @ &lt;a href="https://linguinecode.com/post/get-started-with-react" rel="noopener noreferrer"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;CSS is awesome, and it’s easy to get started with.&lt;/p&gt;

&lt;p&gt;But front-end applications have been scaling at a massive, and complex rate that I don’t believe the current CSS architecture is designed for the job.&lt;/p&gt;

&lt;p&gt;I still believe that the current CSS architecture has a place in this crazy world for small sites, and even small applications.&lt;/p&gt;

&lt;p&gt;I’m going to list a set of problems that I’ve come across with CSS over the 9 years of developing for the web.&lt;/p&gt;

&lt;p&gt;And I believe CSS in JS solves these problems.&lt;/p&gt;

&lt;p&gt;I will be demonstrating how CSS in JS solves these issues by using 2 libraries Styled Components and React.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS problem #1: Global namespace
&lt;/h2&gt;

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

&lt;p&gt;I created a style sheet that contains CSS code for a &lt;em&gt;container&lt;/em&gt; element.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;container&lt;/em&gt; style will increase in size if it also contains the class name &lt;em&gt;home&lt;/em&gt;.&lt;/p&gt;

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




&lt;p&gt;Now I have created the home page HTML, imported the stylesheet, and have added the class names to the HTML elements.&lt;/p&gt;

&lt;p&gt;But wait, I need an about page! Let’s create that now.&lt;/p&gt;

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

&lt;p&gt;I’ve now created the about HTML page, imported the style sheet, and created a new container element.&lt;/p&gt;

&lt;p&gt;Great, right?&lt;/p&gt;

&lt;p&gt;Not exactly. The style sheet that I imported contains styles from the home page.&lt;/p&gt;

&lt;p&gt;And there is nothing to stop me from using class names that was designed for the home page.&lt;/p&gt;

&lt;p&gt;Over time this simple site will grow to have thousands of lines of CSS, and HTML code.&lt;/p&gt;

&lt;p&gt;And CSS rules that have been defined in the past will be re-used across the site. The problem lies when a engineer attempts to change a class rule.&lt;/p&gt;

&lt;p&gt;It has a very high potential of breaking or changing other parts of the site that were not meant to be modified.&lt;/p&gt;

&lt;p&gt;CSS in JS allows us to keep styles encapsulated to a React element.&lt;/p&gt;

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

&lt;p&gt;I’ve created 2 components here.&lt;/p&gt;

&lt;p&gt;The first component is named, &lt;strong&gt;Title&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Title&lt;/strong&gt; is responsible only for styling., The second component is &lt;strong&gt;Greet&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Greet&lt;/strong&gt; is responsible using the styled component that I created and displaying the greet message to the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Title&lt;/strong&gt; been defined as a local style. No other React component or HTML element will be able to access these styles. Safe!&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS problem #2: Implicit dependencies
&lt;/h2&gt;

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

&lt;p&gt;This is called style of writing SASS/CSS is called BEM. Ever heard of it?&lt;/p&gt;

&lt;p&gt;Probably not.&lt;/p&gt;

&lt;p&gt;BEM is one of many CSS methodologies. And the objective with a CSS methodology is to reduce the lack of built-in scoping mechanism.&lt;/p&gt;

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

&lt;p&gt;OOCSS is a method to separate containers and content with CSS “objects”.&lt;/p&gt;

&lt;p&gt;We also have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  SMACSS&lt;/li&gt;
&lt;li&gt;  SUITCSS&lt;/li&gt;
&lt;li&gt;  Atomic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nonetheless, each of these solutions are just a quick patch solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS problem #3: Dead code elimination
&lt;/h2&gt;

&lt;p&gt;Why download CSS code that isn’t going to be used?&lt;/p&gt;

&lt;p&gt;CSS in JS can dynamically clean up CSS code that is not being used.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS problem #4: Minification
&lt;/h2&gt;

&lt;p&gt;CSS out of the box doesn’t have a feature to minify code.&lt;/p&gt;

&lt;p&gt;For big applications unminified CSS code can get fairly big, especially with crazy amount of white space (indentation) we add to the stylesheet.&lt;/p&gt;

&lt;p&gt;To minify CSS code you’ll have to use a third party service online or setup dev task to minify your code.&lt;/p&gt;

&lt;p&gt;Which just creates another dependency your CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS problem #5: Sharing constants
&lt;/h2&gt;

&lt;p&gt;CSS supports a sharing constants with their built-in function called var().&lt;/p&gt;

&lt;p&gt;But it does not support IE. And it barely supports Edge 15.&lt;/p&gt;

&lt;p&gt;We can say, “Microsoft stop support of these browsers.”&lt;/p&gt;

&lt;p&gt;But according to W3Schools, which they get 50 million visits per &lt;strong&gt;month&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;They say 4% comes from IE and Edge.&lt;/p&gt;

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

&lt;p&gt;That’s a total of 2 million users using IE and Edge. Not really numbers that we can ignore.&lt;/p&gt;

&lt;p&gt;And with a recent project with Verizon Media, the application needed to support IE 9 still.&lt;/p&gt;

&lt;p&gt;So var(), goes right out the door. For the moment.&lt;/p&gt;

&lt;p&gt;Another con is that CSS variables cannot be accessed on the server side either.&lt;/p&gt;

&lt;p&gt;Let’s take the React example above and modify it a bit to see how we can use constants across our application.&lt;/p&gt;

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

&lt;p&gt;I created a new file named constants.js, and inside that file it contains a value for the primary text color, FireBrick.&lt;/p&gt;

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

&lt;p&gt;I than updated the Greet component to use the new constant I created.&lt;/p&gt;

&lt;p&gt;First I imported the new constant into the Greet.js file. Then I use a technique called interpolation inside the &lt;strong&gt;Title&lt;/strong&gt; component.&lt;/p&gt;

&lt;p&gt;The hard-coded color value was swapped for the constant.&lt;/p&gt;

&lt;p&gt;While I’m at it, I’ll create a new component called Button, and it will use the same constant.  &lt;/p&gt;

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

&lt;p&gt;The only difference is that primaryTextColor is now being used in 2 css properties for the Button component.&lt;/p&gt;

&lt;p&gt;The components will stay consistent now.  &lt;/p&gt;

&lt;h2&gt;
  
  
  CSS in JS benefits
&lt;/h2&gt;

&lt;p&gt;Besides solving those 5 issues above, it comes with some additional benefits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Generates minimum CSS requires&lt;/li&gt;
&lt;li&gt;  Good runtime performance&lt;/li&gt;
&lt;li&gt;  Supports dynamic styling&lt;/li&gt;
&lt;li&gt;  Easy to pre-render important CSS&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;At the end of the day we’re not getting rid of CSS. We’re just adding JavaScript to enhance CSS.&lt;/p&gt;

&lt;p&gt;The old CSS architecture is perfectly fine for small sites, and small applications.&lt;/p&gt;

&lt;p&gt;But it may not be appropriate choice for medium to big size applications in 2019.&lt;/p&gt;

&lt;p&gt;Sure, we can add SASS, methodologies, and even CSS modules into the mix, but again, those are small patches that require strict rules, and tooling.&lt;/p&gt;

&lt;p&gt;Those are not solutions for the future.&lt;/p&gt;

&lt;p&gt;I would say that CSS in JS is not the ultimate solution, but it’s the best one we have so far.&lt;/p&gt;

&lt;p&gt;Let me know your thoughts and comments on &lt;a href="https://twitter.com/intent/tweet?text=%3Center%20thoughts%20here%3E%20https%3A%2F%2Fblog.linguinecode.com%2Fpost%2F5-reasons-css-in-js%20%40rleija_" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Start building React applications with ease</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Sat, 16 Mar 2019 13:19:05 +0000</pubDate>
      <link>https://forem.com/rleija_/start-building-react-applications-with-ease-2l6n</link>
      <guid>https://forem.com/rleija_/start-building-react-applications-with-ease-2l6n</guid>
      <description>&lt;p&gt;&lt;em&gt;original post @ &lt;a href="https://linguinecode.com/post/get-started-with-react" rel="noopener noreferrer"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;React is the new shiny toy in the JavaScript community, and most industries are leaning towards to using that technology.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fjs-framework-trends.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fjs-framework-trends.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may be coming from Angular, jQuery, or even Backbone, and learning a new tool may sound daunting or even scary.&lt;/p&gt;

&lt;p&gt;No need to fear, in this article I will go over some easy methods to get a React application started in matter of minutes.&lt;/p&gt;

&lt;p&gt;But Before we start, why React though?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why choose React
&lt;/h2&gt;

&lt;p&gt;Reason #1 to choose React, it’s only a UI builder.&lt;/p&gt;

&lt;p&gt;Tools like Angular, and Ember are full blown JavaScript frameworks that require you to do their way.&lt;/p&gt;

&lt;p&gt;And that’s okay, but React doesn’t make any assumptions about your application. It doesn’t force you to rewrite your entire app.&lt;/p&gt;

&lt;p&gt;Reason #2 to pick React is because it’s component based.&lt;/p&gt;

&lt;p&gt;React encapsulates all the CSS, UI, state, and events in a single file OR directory.&lt;/p&gt;

&lt;p&gt;It makes it easy for engineers to digest a large code base because it’s in smaller chunks.&lt;/p&gt;

&lt;p&gt;Reason #3 to pick React is because is declarative.&lt;/p&gt;

&lt;p&gt;It allows you to write declarative views which makes it easy to maintain and debug down the line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting with CDN links
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Source to CDN links:&lt;/em&gt; &lt;a href="https://reactjs.org/docs/cdn-links.html" rel="noopener noreferrer"&gt;&lt;em&gt;https://reactjs.org/docs/cdn-links.html&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the easiest method to get started.&lt;/p&gt;

&lt;p&gt;You just need to import React and React DOM through script tags.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Freact-cdn-links-1.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Freact-cdn-links-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can then create a JavaScript file begin creating your first React component in plain JavaScript.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Freact-plain-js.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Freact-plain-js.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The output should 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Freact-plain-js-output.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Freact-plain-js-output.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next few methods require you to have &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; installed on your machine.&lt;/p&gt;

&lt;p&gt;Once it is installed, NPM command client tool will be available in the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting with Create React App
&lt;/h2&gt;

&lt;p&gt;This is one of the easiest methods to get a new project up and running.&lt;/p&gt;

&lt;p&gt;Run the command down below.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fcreate-react-app-terminal.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fcreate-react-app-terminal.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NPX comes with NPM 5.2+. NPX allows you not install Create React App on your machine.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I’m calling Create React App to create our project in a directory named, test-app.&lt;/p&gt;

&lt;p&gt;Create React App will then download all the dependencies that it comes with.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://camo.githubusercontent.com/29765c4a32f03bd01d44edef1cd674225e3c906b/68747470733a2f2f63646e2e7261776769742e636f6d2f66616365626f6f6b2f6372656174652d72656163742d6170702f323762343261632f73637265656e636173742e737667" class="article-body-image-wrapper"&gt;&lt;img src="https://camo.githubusercontent.com/29765c4a32f03bd01d44edef1cd674225e3c906b/68747470733a2f2f63646e2e7261776769742e636f6d2f66616365626f6f6b2f6372656174652d72656163742d6170702f323762343261632f73637265656e636173742e737667"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The video above is from &lt;a href="https://github.com/facebook/create-react-app" rel="noopener noreferrer"&gt;create react app&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once Create React App has completed installing the dependencies it will then ask you to go into your project directory (via terminal) and execute the following commands.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fstart-create-react-app.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fstart-create-react-app.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By running npm start, Create React App development will kick in and open you&lt;/p&gt;

&lt;p&gt;Create React App doesn’t just install a few node module dependencies, but it also provides the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  JSX, ES6, and TypeScript Support&lt;/li&gt;
&lt;li&gt;  Auto prefixed CSS&lt;/li&gt;
&lt;li&gt;  Hot reloading for development&lt;/li&gt;
&lt;li&gt;  A build script to bundle your JavaScript, CSS, and images&lt;/li&gt;
&lt;li&gt;  Progressive Web App ready&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fcreate-react-app-example-1.jpg" 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fcreate-react-app-example-1.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty simple to start with Create React App, but this is just a JavaScript site at the end of the day.&lt;/p&gt;

&lt;p&gt;What if you want to build your own personal site, should you use Create React App?&lt;/p&gt;

&lt;p&gt;Probably not, because JavaScript sites don’t benefit you in SEO.&lt;/p&gt;

&lt;p&gt;You’re going to need something that let’s you build the UI of your website with React and renders it with a server language such as Node.js.&lt;/p&gt;

&lt;p&gt;Now we can do this setup manually, but why?&lt;/p&gt;

&lt;p&gt;There are plenty of great open source tools out there that do that for us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting with Next.js
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Resource link: &lt;a href="https://github.com/zeit/next.js/tree/master" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Next.js is my framework of choice to create server side rendered React applications or sites.&lt;/p&gt;

&lt;p&gt;Next.js is lightweight, progressive web app ready, and most importantly, SEO friendly.&lt;/p&gt;

&lt;p&gt;By the way, this site (&lt;a href="https://blog.linguinecode.com" rel="noopener noreferrer"&gt;blog.linguinecode.com&lt;/a&gt;) you’re reading off is using Next.js to power the front-end!&lt;/p&gt;

&lt;p&gt;Next.js does require a few more steps but it’s nothing to hard. I’ll walk you through it.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Finstalling-next.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Finstalling-next.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First I created a new directory for my site, and called it test-site.&lt;/p&gt;

&lt;p&gt;The next step is to install 3 node module dependencies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Next&lt;/li&gt;
&lt;li&gt;  React&lt;/li&gt;
&lt;li&gt;  React DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We briefly spoke about React, and React DOM earlier in this article.&lt;/p&gt;

&lt;p&gt;Those 2 libraries will help me create React code and dump it to the DOM.&lt;/p&gt;

&lt;p&gt;The next dependency I installed is Next.&lt;/p&gt;

&lt;p&gt;Next is what will help me bridge the gap between Node.js and React.&lt;/p&gt;

&lt;p&gt;Next.js is responsible to serve your site through server code first, and let JavaScript aka React to handle loading the rest of the site as a user navigates around.&lt;/p&gt;

&lt;p&gt;JavaScript is fast, once it’s loaded, so we aid the load speed by letting Node.js do the first load of the site.&lt;/p&gt;

&lt;p&gt;The next step is to create a package.json file and add the following lines of code.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnext-package-json.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnext-package-json.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The important lines are in the scripts object.&lt;/p&gt;

&lt;p&gt;Running npm run dev will spin up development mode.&lt;/p&gt;

&lt;p&gt;Running npm run build will build, and optimize the site or application for production.&lt;/p&gt;

&lt;p&gt;And running npm run start will run your production build.&lt;/p&gt;

&lt;p&gt;Fairly simple, but now I’m going to start adding a couple pages.&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-structure.jpg" 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-structure.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what a typical Next.js project structure looks like.&lt;/p&gt;

&lt;p&gt;The directory pages, is extremely important when using this framework.&lt;/p&gt;

&lt;p&gt;That’s because Next.js will look each file inside that directory and create routes based on the file name.&lt;/p&gt;

&lt;p&gt;So index.js will represent the front page of the site/application&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-home-page.jpg" 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-home-page.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And about.js will look like:&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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-about-page.jpg" 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-about-page.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s great but what does the code in each page look like?!&lt;/p&gt;

&lt;p&gt;That’s a great question, it’s just a React 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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-about-page-code.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%2Fs3.amazonaws.com%2Flinguine-code-cdn%2Fmedia%2Fnextjs-about-page-code.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a beautiful thing because Next.js just lets you focus on the UI of your website or application.&lt;/p&gt;

&lt;p&gt;There’s another neat little feature that Next.js provides to the developer.&lt;/p&gt;

&lt;p&gt;Next.js provides a static method to your React component called getInitialProps.&lt;/p&gt;

&lt;p&gt;This static method is only provided in the React components found in the pages directory. No children component have access to this static method.&lt;/p&gt;

&lt;p&gt;getIntialProps runs both on server and client side of the application/site.&lt;/p&gt;

&lt;p&gt;That’s where you can typcically make fetch calls to API’s. This will help make sure that the page is populated with content before serving it to the user.&lt;/p&gt;

&lt;p&gt;In the example above, I’m just returning the isServer variable that’s provided.&lt;/p&gt;

&lt;p&gt;It let’s my site know if the page was accessed on the server side or client side.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article I go over some of the easiest ways to initialize and get right in coding React applications.&lt;/p&gt;

&lt;p&gt;Getting started with React may seem tricky and complicated. But with the enormous amount of support from the community, starting a React app can be matter of minutes.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Introducing the new kid on the block, React hooks</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Mon, 11 Mar 2019 13:06:52 +0000</pubDate>
      <link>https://forem.com/rleija_/introducing-the-new-kid-on-the-block-react-hooks-3jhh</link>
      <guid>https://forem.com/rleija_/introducing-the-new-kid-on-the-block-react-hooks-3jhh</guid>
      <description>&lt;p&gt;Article has been moved to: &lt;a href="https://linguinecode.com/post/getting-started-with-react-hooks"&gt;Getting started with React Hooks&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Master the art of React state and props in 5 minutes</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Thu, 07 Mar 2019 04:19:59 +0000</pubDate>
      <link>https://forem.com/rleija_/master-the-art-of-react-state-and-props-in-5-minutes-3hao</link>
      <guid>https://forem.com/rleija_/master-the-art-of-react-state-and-props-in-5-minutes-3hao</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published @ &lt;a href="https://linguinecode.com/post/master-react-state-and-props" rel="noopener noreferrer"&gt;Linguine Blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A common newbie question for engineers learning React is, “what’s the difference between props and state?” Or googling “React: props vs state”.&lt;/p&gt;

&lt;p&gt;I spent hours trying to understand the difference when I first started, and I came to find out that most articles teach it the wrong the way.&lt;/p&gt;

&lt;p&gt;Most articles begin with learning what props means first, and React state second. But I think that’s the wrong way to learn what React state and props are and how they work together.&lt;/p&gt;

&lt;p&gt;So we’ll start by learning what React state is first.&lt;/p&gt;

&lt;h2&gt;
  
  
  React state is
&lt;/h2&gt;

&lt;p&gt;Let’s begin by defining what is React state.&lt;/p&gt;

&lt;p&gt;React state is an object.&lt;/p&gt;

&lt;p&gt;React state can be private or public to it’s children components.&lt;/p&gt;

&lt;p&gt;React state may hold information that influences the output of a React component.&lt;/p&gt;

&lt;h2&gt;
  
  
  React state in action
&lt;/h2&gt;

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

&lt;p&gt;The first block of code we see is a simple cat react app. The objective to this cat app is to nail each definition listed above.&lt;/p&gt;

&lt;p&gt;Now let’s create our React state.&lt;/p&gt;

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

&lt;p&gt;That’s how easy it was!&lt;/p&gt;

&lt;p&gt;But this empty state object is kind of useless until we start adding some data into it.&lt;/p&gt;

&lt;p&gt;So we’re going to add a new property (not React component props) to that state object, and will add a couple of JavaScript events to handle adding a new cat name.&lt;/p&gt;

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

&lt;p&gt;Okay, this got complicated real quick! But I’ll break it down for you really easily.&lt;/p&gt;

&lt;p&gt;First, our state object has 2 new properties.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;nameOfNewCat,&lt;/em&gt; will hold the new name for your cat as you’re typing.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;cats,&lt;/em&gt; is another new property that will hold a list of your cats names.&lt;/p&gt;

&lt;p&gt;In our &lt;em&gt;render()&lt;/em&gt; method, I’ve added a input tag, and I’ve bind 2 actions to the button, and input tag.&lt;/p&gt;

&lt;p&gt;This is important for you to note, because each action (&lt;em&gt;handleChange&lt;/em&gt;, and &lt;em&gt;handleAddCatClick&lt;/em&gt;) is modifying the state object.&lt;/p&gt;

&lt;p&gt;Let’s break the &lt;em&gt;handleChange&lt;/em&gt; action so you may understand how to modify state the right way.&lt;/p&gt;

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

&lt;p&gt;Notice how we’re using &lt;em&gt;this.setState()&lt;/em&gt;. This is the correct way of modifying any property in a React state object.&lt;/p&gt;

&lt;p&gt;In traditional JavaScript, you would typically modify the object directly. But that’s a big no no in practice.&lt;/p&gt;

&lt;p&gt;This is because modifying the state directly may create a situation where those modifications may get overwritten and cause inconsistency in the app.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;setState&lt;/em&gt;, does not modify directly but creates a pending state transition.&lt;/p&gt;

&lt;p&gt;Another important thing to note is when you’re updating your React state tree, it only modifies the first level of properties.&lt;/p&gt;

&lt;p&gt;Huh??&lt;/p&gt;

&lt;p&gt;Look at the example below to see what I mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to update nested state objects with setState()
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;P.S. the example below is not part of the cat app we’re working on.&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;From the image above it shows an example of a state object that has properties such as name, age, and likes for dogs and cats.&lt;/p&gt;

&lt;p&gt;If you run &lt;em&gt;setState&lt;/em&gt; to change the value of &lt;em&gt;name&lt;/em&gt;, than React will keep the other values that are defined and only change the &lt;em&gt;name&lt;/em&gt; property.&lt;/p&gt;

&lt;p&gt;You might think that only modifying a specific property will change and will keep the rest of the values as is. But you’re wrong if you think that.&lt;/p&gt;

&lt;p&gt;As shown above, if we update the likes for &lt;em&gt;cats&lt;/em&gt; to false. You’ll see that the state object has removed our like for &lt;em&gt;dogs&lt;/em&gt;. And we all love dogs!&lt;/p&gt;

&lt;p&gt;To keep our like for dogs, we must tell &lt;em&gt;setState&lt;/em&gt; that we want to keep our previous nested values.&lt;/p&gt;

&lt;p&gt;In ES6, we can do something called the spread operator. And as you see in the final results we keep our love for dogs and change our love for cats.&lt;/p&gt;

&lt;h2&gt;
  
  
  React state influencing the output
&lt;/h2&gt;

&lt;p&gt;We’ve discussed about what React state is and how to add, and update React state data.&lt;/p&gt;

&lt;p&gt;Your next question might be, “how do we display the data we’ve saved in state?”&lt;/p&gt;

&lt;p&gt;This is done really easily.&lt;/p&gt;

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




&lt;p&gt;In our cat app, we just need to grab the &lt;em&gt;cats&lt;/em&gt; property from your React state object and render some markup for each cat.&lt;/p&gt;

&lt;p&gt;In the image above you will be looping through each cat using the .&lt;em&gt;map()&lt;/em&gt; array method to create a new &lt;em&gt;li&lt;/em&gt; tag that outputs the name of the cat we’ve entered.&lt;/p&gt;

&lt;p&gt;The output should look something like this.&lt;/p&gt;

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

&lt;p&gt;So far we’ve built a React cat application that utilizes state to save, and display data.&lt;/p&gt;

&lt;p&gt;Now we must understand how React props plays nicely with state.&lt;/p&gt;

&lt;h2&gt;
  
  
  The definition of React props
&lt;/h2&gt;

&lt;p&gt;Let’s begin by defining what a React prop is.&lt;/p&gt;

&lt;p&gt;React props are inputs that describe what we should see.&lt;/p&gt;

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

&lt;p&gt;Above is an example of a plain a text field, and I have inserted an input of &lt;em&gt;type&lt;/em&gt; to equal &lt;strong&gt;text&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And if I add another input named &lt;em&gt;placeholder&lt;/em&gt;, it will make my input field look different to the user.&lt;/p&gt;

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

&lt;p&gt;&lt;em&gt;inputs&lt;/em&gt; equal &lt;strong&gt;props&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It works the same way with React components. Let’s take a look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing state data as props
&lt;/h2&gt;

&lt;p&gt;In the same file, you can create a new React component called Cat. Cat will expect a prop called &lt;em&gt;name&lt;/em&gt;.&lt;/p&gt;

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

&lt;p&gt;You will now update the code in the CatApp component where you’re displaying the list of cat names.&lt;/p&gt;

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

&lt;p&gt;All you’re doing here is passing the cat name that we’ve stored in our &lt;em&gt;state&lt;/em&gt; object, and passing it as a &lt;em&gt;prop&lt;/em&gt; to the Cat component you’ve created.&lt;/p&gt;

&lt;p&gt;The Cat component will then display the input name, and display the name in a list item HTML tag.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Understanding React state and props can seem challenging and some what confusing.&lt;/p&gt;

&lt;p&gt;But learning it the right order may help you understand it quicker and better.&lt;/p&gt;

&lt;p&gt;State is an object that contains private or public local data about a component. And it may be used to influence the output of a component.&lt;/p&gt;

&lt;p&gt;Props are nothing more than input definitions to describe what you are suppose to see.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
