<?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>DEV Community: Laura Todd</title>
    <description>The latest articles on DEV Community by Laura Todd (@lauratoddcodes).</description>
    <link>https://dev.to/lauratoddcodes</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%2F594539%2F8fc10a43-6e49-4670-b4ae-a973f37b4c74.jpg</url>
      <title>DEV Community: Laura Todd</title>
      <link>https://dev.to/lauratoddcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lauratoddcodes"/>
    <language>en</language>
    <item>
      <title>Using the useContext hook in React</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 24 Jul 2022 13:55:10 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/using-the-usecontext-hook-in-react-3kob</link>
      <guid>https://dev.to/lauratoddcodes/using-the-usecontext-hook-in-react-3kob</guid>
      <description>&lt;p&gt;Sometimes when you're building an app in React, it can be difficult to pass props from one component to another without prop drilling. One of the in-built tools that React has to tackle this issue is the useContext hook.&lt;/p&gt;

&lt;p&gt;The React's Context allows you to wrap your components in a context provider. The values which you need to share throughout your components can then be initialised at the top level and then accessed in any component using the useContext hook.&lt;/p&gt;

&lt;p&gt;Let's take a look at a simple example.&lt;/p&gt;

&lt;p&gt;Let's say we have an App which contains two components - one is a text input and the other is a component which will display the value that the user enters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr39sf7bgvh6er2nrlp88.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr39sf7bgvh6er2nrlp88.gif" alt="user types name in input field and it displays below"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the file structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq45ew9nmbtozqrkkpp4j.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq45ew9nmbtozqrkkpp4j.jpg" alt="App component has two child components - Input and Result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, we can't simply pass the input value between the Input and Result siblings. In reality, in this very simple example, the best way of dealing with the issue would be to lift the state to the App component and then pass it down to each of the child components. But let's say you were building a more complex app and you needed to pass the state down several levels of the component tree while avoiding prop drilling - that's where Context comes in.&lt;/p&gt;

&lt;p&gt;The starter files for this example can be found &lt;a href="https://github.com/LauraToddCodes/using-usecontext/tree/starting-code" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, we want to create a new file and create our context using &lt;code&gt;React.createContext&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from "react"

export type InputValues = {
  nameValue: string
  setNameValue: React.Dispatch&amp;lt;React.SetStateAction&amp;lt;string&amp;gt;&amp;gt;
}

export const InputContext = React.createContext&amp;lt;InputValues&amp;gt;({
  nameValue: "",
  setNameValue: () =&amp;gt; console.info("Name not yet initialised"),
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the createContext object, you will need to add and initialise any values that you need to. Here, we've set up &lt;code&gt;nameValue&lt;/code&gt; which will be used in the Result component to display the name and the &lt;code&gt;setNameValue&lt;/code&gt; which will be used to set the value in the Input component.&lt;/p&gt;

&lt;p&gt;Next, we'll create our own hook which we can use later in the provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from "react"

import { InputValues } from "./input-context"

export function useInputProvider(): InputValues {
  const [nameValue, setNameValue] = React.useState("")

  return {
    nameValue,
    setNameValue,
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we simply set up &lt;code&gt;nameValue&lt;/code&gt; and &lt;code&gt;setNameValue&lt;/code&gt; with the React useState hook and return them to use in our next step.&lt;/p&gt;

&lt;p&gt;Now we need to go to our App file and wrap our Input and Result components in a context provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Input, Result } from "./components"

import { InputContext } from "./context"
import { useInputProvider } from "./context/use-input-provider"

function App() {
  const nameValue = useInputProvider()

  return (
    &amp;lt;div className="inputForm"&amp;gt;
      &amp;lt;InputContext.Provider value={nameValue}&amp;gt;
        &amp;lt;Input /&amp;gt;
        &amp;lt;Result /&amp;gt;
      &amp;lt;/InputContext.Provider&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, we use the &lt;code&gt;InputContext&lt;/code&gt; that we set up in the first step and wrap the child components in the provider. We can then use the &lt;code&gt;useInputProvider&lt;/code&gt; hook that we set up in the second step to pass &lt;code&gt;nameValue&lt;/code&gt; and &lt;code&gt;setNameValue&lt;/code&gt; as the Provider value.&lt;/p&gt;

&lt;p&gt;Now that we've set up the provider, how do we access the values in our child components?&lt;/p&gt;

&lt;p&gt;First, let's go to our Input component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from "react"
import { InputContext } from "../context"

export function Input(): JSX.Element {
  const { setNameValue } = React.useContext(InputContext)

  function handleChange(e: React.ChangeEvent&amp;lt;HTMLInputElement&amp;gt;) {
    setNameValue(e.target.value)
  }

  return (
    &amp;lt;form&amp;gt;
      &amp;lt;label htmlFor="name"&amp;gt;Name: &amp;lt;/label&amp;gt;
      &amp;lt;input type="text" id="name" name="name" onChange={handleChange} /&amp;gt;
    &amp;lt;/form&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we need to access &lt;code&gt;setNameValue&lt;/code&gt; in order to set the name value to whatever the user types in the input field. To do this, we can use the &lt;code&gt;useContext&lt;/code&gt; hook and pass in our &lt;code&gt;InputContext&lt;/code&gt;. You can then extract &lt;code&gt;setNameValue&lt;/code&gt; like this -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { setNameValue } = React.useContext(InputContext)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can then go ahead and use &lt;code&gt;setNameValue&lt;/code&gt; to take in the input value.&lt;/p&gt;

&lt;p&gt;Finally, let's go over to our Result component and access &lt;code&gt;nameValue&lt;/code&gt; in the same way using &lt;code&gt;useContext&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from "react"
import { InputContext } from "../context"

export function Result() {
  const { nameValue } = React.useContext(InputContext)
  return &amp;lt;div&amp;gt;{nameValue}&amp;lt;/div&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then pass the &lt;code&gt;nameValue&lt;/code&gt; into the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; to display the result.&lt;/p&gt;

&lt;p&gt;And that's it! You can find the completed code &lt;a href="https://github.com/LauraToddCodes/using-usecontext/tree/main" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>props</category>
    </item>
    <item>
      <title>The Best Colour Palette Tools</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 06 Jun 2021 11:52:12 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/the-best-colour-palette-tools-28f8</link>
      <guid>https://dev.to/lauratoddcodes/the-best-colour-palette-tools-28f8</guid>
      <description>&lt;p&gt;Colour is such an important aspect of web design. It can set a mood, highlight important elements and ensure consistency in your branding.&lt;/p&gt;

&lt;p&gt;Unfortunately, I'm terrible at choosing a colour palette. If I select colours at random to use in my projects, it ends up looking like a dog's dinner. Thankfully, there are plenty of tools out there to help you find shades that compliment each other. I'll take you through the ones I use the most.&lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8vzr8iu0den53fdzefo.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8vzr8iu0den53fdzefo.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Canva
&lt;/h3&gt;

&lt;p&gt;Canva has a huge range of colour schemes, each of 4 colours. You can browse through or search by colour, theme or keyword to find the palette to suit your project.&lt;/p&gt;

&lt;p&gt;There's even a feature which allows you to upload a photo and Canva will pick out the prominent colours for you.&lt;/p&gt;

&lt;p&gt;If you already have a particular colour in mind that you want to use, there's the colour wheel tool which allows you to enter the hex code and generates a series of palettes that work with that colour depending on what you're trying to achieve. You can choose to find a complimentary, monochromatic, analogous, triadic or tetradic set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;url:&lt;/strong&gt; &lt;a href="https://www.canva.com/colors" rel="noopener noreferrer"&gt;https://www.canva.com/colors&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;
 &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcizxno6pb32y1um1uk8q.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcizxno6pb32y1um1uk8q.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Coolors
&lt;/h3&gt;

&lt;p&gt;Coolors generates random colour palettes when you hit spacebar. If you spot a colour you like the look of, you can lock it in place and continue hitting spacebar to find other colours to go with it. &lt;/p&gt;

&lt;p&gt;If you find a colour or even an entire palette that you like but want it a little more saturated or bright, you can adjust them with the 'Adjust Palette' tool.&lt;/p&gt;

&lt;p&gt;A great feature of Coolors is the gradient maker. Choose two colours and create a gradient between the two (either radial or linear), it then generates the CSS for you so that all you have to do is copy and paste it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;url:&lt;/strong&gt; &lt;a href="https://coolors.co/" rel="noopener noreferrer"&gt;https://coolors.co/&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;
 &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1jr8zocnwc7zi9vsskjp.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1jr8zocnwc7zi9vsskjp.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Colormind
&lt;/h3&gt;

&lt;p&gt;Much like Coolors, Colormind, allows you to generate different colour palettes randomly and lock in place any colours you particularly like.&lt;/p&gt;

&lt;p&gt;In addition to that, it makes suggestions of how to use each colour within your site - great for those of us who need a little extra help in that area.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;url:&lt;/strong&gt; &lt;a href="http://colormind.io/bootstrap/" rel="noopener noreferrer"&gt;http://colormind.io/bootstrap/&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7sssge524y63m0f1gec.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7sssge524y63m0f1gec.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Colorable
&lt;/h3&gt;

&lt;p&gt;Colorable isn't quite as 'all singing, all dancing' as most of the other tools on the list. However, it does one thing particularly well - it generates paired colours, showing the page text in one colour and the background in the other. This is particularly good for web design as you can immediately get a feel for the way the colours work on a webpage.&lt;/p&gt;

&lt;p&gt;You can also add in one of your own colours to find something that will work well alongside it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;url:&lt;/strong&gt; &lt;a href="https://colorable.jxnblk.com/021b00/7251ac" rel="noopener noreferrer"&gt;https://colorable.jxnblk.com/021b00/7251ac&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;
 &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwjl6w24dpukf85tabsf.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwjl6w24dpukf85tabsf.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Happy Hues
&lt;/h3&gt;

&lt;p&gt;Similarly to Colorable, Happy Hues gives you an idea of how varying colour palettes will look on a webpage but with a palette of 5 rather than 2 colours.&lt;/p&gt;

&lt;p&gt;It has a range of curated colour palettes and suggests how, and on which elements, you could use them on a generic website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;url:&lt;/strong&gt; &lt;a href="https://www.happyhues.co/palettes/12" rel="noopener noreferrer"&gt;https://www.happyhues.co/palettes/12&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;
 &lt;br&gt;
Of course, there are plenty of other tools out there but these are just some that I use regularly. If you know of any other good resources out there why not add it in the comments section?&lt;/p&gt;

</description>
      <category>css</category>
      <category>styling</category>
      <category>webdesign</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Using the Google Maps API in React</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 23 May 2021 14:54:51 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/using-the-google-maps-api-in-react-31ph</link>
      <guid>https://dev.to/lauratoddcodes/using-the-google-maps-api-in-react-31ph</guid>
      <description>&lt;p&gt;The Google Maps JavaScript API is a great way to include an interactive map on your website and gives you heaps of options for controlling and customising it. In this post, I'll take you through how to create a map with multiple, customised markers and info windows which appear on click.&lt;/p&gt;

&lt;p&gt;We'll end up with something like this -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivy5ys3r0kwkj3fi787l.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivy5ys3r0kwkj3fi787l.jpg" alt="final result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To do this exercise, you'll need your own API key from Google. Since I only really want to concentrate on getting the map working in React, I'm going to assume you already have one. If you don't, and don't know how to get one, &lt;a href="https://www.youtube.com/watch?v=YKI3nE6pqvM" rel="noopener noreferrer"&gt;this video&lt;/a&gt; shows you how.&lt;/p&gt;

&lt;p&gt;We'll start off with a basic React app. You can find the starting code &lt;span&gt;&lt;a href="https://github.com/LauraToddCode/using-google-maps/tree/starter-code/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;Create a new file called 'properties.json' this is where we'll keep the data for each of the properties we want to show on our map.&lt;/p&gt;

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

&lt;p&gt;Next, install 'react-google-maps'.&lt;/p&gt;

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

&lt;p&gt;Now we need to create our Map component. Make a 'components' folder and inside, add a new file called 'Map.js'. In this file, import 'GoogleMap', 'withScriptjs', 'withGoogleMap', 'Marker' and 'InfoWindow' from 'react-google-maps'. Then create two functional components - 'MapComponent' and 'Map'. Only export 'Map'.&lt;/p&gt;

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

&lt;p&gt;Underneath the 'MapComponent' we need to use the 'withScriptjs' and 'withGoogleMap' functions to wrap the 'MapComponent'. We can then return the 'WrappedMap' inside the 'Map' component.&lt;/p&gt;

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

&lt;p&gt;Now, go back to the 'App.js' file and import your Map component. Render the map component wrapped in two 'divs' like so -&lt;/p&gt;

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

&lt;p&gt;Then, add the following CSS to the stylesheet to display the map at 800 x 500px (or whatever size you'd 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fin7aoskqqjwdimh1rtuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fin7aoskqqjwdimh1rtuh.png" alt="add styling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we need to pass in some properties to the wrapped map. Firstly, the 'googleMapURL' property should be set to &lt;code&gt;https://maps.googleapis.com/maps/api/js? v=3.exp&amp;amp;libraries=geometry,drawing,places&amp;amp;amp;key=[YOUR_API_KEY]&lt;/code&gt; with your own API key replacing [YOUR_API_KEY].&lt;/p&gt;

&lt;p&gt;Then, the 'loadingElement', 'containerElement' and 'mapElement' should all be styled to 100% height to ensure that they take up the whole of their container.&lt;/p&gt;

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

&lt;p&gt;Now let's import our 'properties.json' file as 'properties' and go back to our 'MapComponent' component.&lt;/p&gt;

&lt;p&gt;We can add in some &lt;code&gt;&amp;lt;GoogleMap&amp;gt;&lt;/code&gt; tags and enter the 'defaultZoom' and 'defaultCenter' properties. These are pretty self explanatory - 'defaultZoom' is how far the map is zoomed in when it first renders and 'defaultCenter' is the co-ordinates that the map centers on when it first renders.&lt;/p&gt;

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

&lt;p&gt;Next, we can use the values from our json file to create the markers on our map.&lt;/p&gt;

&lt;p&gt;Inside the &lt;code&gt;&amp;lt;GoogleMap&amp;gt;&lt;/code&gt; tags, use the map() array method to render a &lt;code&gt;&amp;lt;Marker&amp;gt;&lt;/code&gt; for each property, grabbing the id value and the lng and lat values for each one. If you run your app at this point, you should see the default red Google Maps markers.&lt;/p&gt;

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

&lt;p&gt;Next, we can add our own custom icons as markers by adding the 'icon' property. Set the 'url' for your icon and set the 'scaledSize' to 'new window.google.maps.Size(25, 25)'. This will make your icons 25px x 25px.&lt;/p&gt;

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

&lt;p&gt;Finally, we can set up our info windows. In order to do this, we need to know which of the markers is being clicked so that we know which of the windows to show. So lets add an onClick event listener to our markers and use useState to set the selected property.&lt;/p&gt;

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

&lt;p&gt;Now we can use our 'selectedProperty' to render an  with information about our selected property.&lt;/p&gt;

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

&lt;p&gt;That's it! Now you have a map, with multiple custom markers and info windows which display on click.&lt;/p&gt;

&lt;p&gt;You can check your final code &lt;a href="https://github.com/LauraToddCode/using-google-maps/tree/master/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>googlemaps</category>
      <category>api</category>
    </item>
    <item>
      <title>A Really Simple Intro to Redux</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 16 May 2021 13:58:48 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-redux-4h04</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-redux-4h04</guid>
      <description>&lt;p&gt;In a previous post, I took you through using &lt;a href="https://www.lauratodddesign.com/blog/a-really-simple-intro-to-context-in-react/" rel="noopener noreferrer"&gt;React's Context API&lt;/a&gt; as a way to pass data between sibling components. This time, we'll take a look at an alternative way of doing the same thing using Redux. &lt;/p&gt;

&lt;p&gt;Redux is a useful tool which can be used to store state so that it can be used anywhere within your app.&lt;/p&gt;

&lt;p&gt;In this example I'll show you how to make a really simple two-page app in which, on the 'Home' page, the user can save items from a list. Then, when they go over to the 'Saved' page, the saved items will be displayed and can also be removed from there.&lt;/p&gt;

&lt;p&gt;So here's our 'Home' page -&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkramgs1kz0b0ygzjlnnj.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkramgs1kz0b0ygzjlnnj.jpg" alt="home page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if we click to save 'Cow' and 'Pig', then go over to the 'Saved' page, we'll see this -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33sxhscco66zduik8q58.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33sxhscco66zduik8q58.jpg" alt="saved page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I won't go through setting up the app as I just want to focus on Redux in this post. We'll start off with a 3 Components - the Navbar, the Home page and the Saved page. You can find the starting code &lt;span&gt;&lt;a href="https://github.com/LauraToddCode/using-redux/tree/starter-code/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;To begin, lets install the dependencies we'll need - 'redux' and 'react-redux'.&lt;/p&gt;

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

&lt;p&gt;Next we need to set up our files. When using Redux there are quite a few files you'll need to create so it's a good idea to create a new folder to keep them all in. We'll call our folder 'redux'.&lt;/p&gt;

&lt;p&gt;Create a new file called 'rootReducer.js'. Here we'll create our root reducer function and by importing 'combineReducers' from Redux it means that if we needed to add a variety of different reducers to our app, they could all run from one function. We'll leave the function empty for the moment as we need to create another file to import into the function.&lt;/p&gt;

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

&lt;p&gt;Now, create a file called 'store.js'. This will be where our state is stored. We need to import 'createStore', 'composeWithDevTools' and the 'rootReducer' that we just created. Then, we call createStore and pass in the rootReducer.&lt;/p&gt;

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

&lt;p&gt;Next, let's go over to our index.js file and import 'Provider' and the store we just created. We need to wrap the entire app with  tabs and pass in our store so that the entire app can communicate and use information from the store. &lt;/p&gt;

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

&lt;p&gt;Now let's go back over to our redux folder and create another folder within that called 'save'.&lt;/p&gt;

&lt;p&gt;Create a file called 'saveTypes.js' and create two action types. In our case, we only have 2 actions to create - we want to save an item and we want to remove an item from the saved items. We'll call the actions 'SAVE_ITEM' and 'REMOVE_ITEM'.&lt;/p&gt;

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

&lt;p&gt;Now create another file in the 'save' folder called 'saveActions.js'. Here, import the actions we've just created, then create a function for each action. The functions will return an object with two values - the 'type', which will be the action imported from our 'saveTypes' file and the 'payload' which will be the data we want to get and store from the action. In our case, we want to get the id of the selected item.&lt;/p&gt;

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

&lt;p&gt;The final file we need to create in the 'save' folder is 'saveReducer.js'. This is where the action happens! &lt;/p&gt;

&lt;p&gt;Begin by importing the action types from the 'saveTypes' file. Then create an object which initialises the state. First, we want to have a state called items which is an object array of all the items. Secondly we want to have a state for the saved objects. Since we don't want any of the items to be saved when we start, we can initialise this as an empty array.&lt;/p&gt;

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

&lt;p&gt;Next, let's create our saveReducer function and pass in our parameters of state and action. We want to use our INITIAL_STATE as the state so we can add that to the parameters too.&lt;/p&gt;

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

&lt;p&gt;Within the function, we create a switch statement which checks for the action being used. Our default will simply return 'state'.&lt;/p&gt;

&lt;p&gt;First, let's add the SAVE_ITEM action. This action will be used when we click the 'Save' button for any of our animals. When that happens, we want to check for the id of that animal and then add it to the 'savedItems' array.&lt;/p&gt;

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

&lt;p&gt;To do that, we can use the find() method to get the object from our 'items' array whose id matches the id of the selected item (action.payload.id).&lt;/p&gt;

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

&lt;p&gt;We then need to check whether that animal has already been saved as we don't want to add it to our 'savedItems' array twice. Again, we can use the find() method to search the savedItems array.&lt;/p&gt;

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

&lt;p&gt;Now, in our return statement, we can use the spread operator to get our state (...state) and then update our 'savedItems' state. We can use a ternary operator which uses our 'alreadySaved' value and, if the item hasn't already been saved, add the item to our 'savedItems' array. Else it returns the current state.&lt;/p&gt;

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

&lt;p&gt;Next, let's add the case for the REMOVE_ITEM action. Here, we can simply use the filter method to remove the item whose id matches the selected animal.&lt;/p&gt;

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

&lt;p&gt;Now we can go back over to our 'rootReducer' file and import the 'saveReducer' which we can now assign to our 'save' reducer.&lt;/p&gt;

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

&lt;p&gt;Since our app is really simple and only deals with whether the items are saved or not, we only need to include one reducer ('save'). If we were creating a more complex app, we might have a number of reducers which is why we us the 'combineReducers' function. It allows us to combine all of the reducers into one file - the 'rootReducer' file.&lt;/p&gt;

&lt;p&gt;Now that we have all the Redux files set up, we can start introducing the stored state into our components. Let's start by going over to our 'Home' component. &lt;/p&gt;

&lt;p&gt;First, we need to get all of our items from the stored 'items' array so that we can map them on the page. Underneath our functional component, we'll add a new function called 'mapStateToProps' and pass in state as a parameter. This function will return the items stored in state meaning that we can use them in our component by using the key value 'items'.&lt;/p&gt;

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

&lt;p&gt;Next, import 'connect' from 'react-redux' and use this function to connect the 'Home' component to the redux store.&lt;/p&gt;

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

&lt;p&gt;We can then pass our 'items' array into the Home function and use the map() method to display the values on the 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmfi5cwxv5c851e6con0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmfi5cwxv5c851e6con0.png" alt="map items array"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to save our items, we need to add the SAVE_ITEM action to our button by using the 'saveItem' function we created in the 'saveActions' file. First, import the function. Then, below our 'mapStateToProps' function, add a new function called 'mapDispatchToProps' and pass it into the connect function.&lt;/p&gt;

&lt;p&gt;Where the 'mapStateToProps' function was retrieving information from the store, the 'mapDispatchToProps' function updates the information in the store.&lt;/p&gt;

&lt;p&gt;Within the 'mapDispatchToProps' function we use the 'saveItem' function to get the id of the item and add it to the 'savedItems' array.&lt;/p&gt;

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

&lt;p&gt;Now, pass 'saveItem' into the 'Home' component and add it to an onClick event in the button element, collecting the id of the animal being saved.&lt;/p&gt;

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

&lt;p&gt;If we then go over to our 'Saved' component, we can repeat the same steps we used for the 'Home' component with some slight differences.&lt;/p&gt;

&lt;p&gt;Instead of mapping the items in the 'items' array, we want to map the items from the 'savedItems' array and instead of using the 'saveItem' function on the button, we want to use the 'removeItem' function.&lt;/p&gt;

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

&lt;p&gt;That's it! If you open up your app, you should be able to save and remove items from the Saved page.&lt;/p&gt;

&lt;p&gt;You can check your final code &lt;span&gt;&lt;a href="https://github.com/LauraToddCode/using-redux/tree/master/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>redux</category>
      <category>state</category>
    </item>
    <item>
      <title>A Really Simple Intro to localStorage in React</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 09 May 2021 13:37:49 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-localstorage-in-react-35e3</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-localstorage-in-react-35e3</guid>
      <description>&lt;p&gt;Saving information to local storage can be incredibly useful and can make for a far better user experience in your apps. Imagine if you had to log in from scratch every time you wanted to look at Twitter! &lt;/p&gt;

&lt;p&gt;By using the localStorage method in React, we can make save certain information to the user's machine to save them re-entering it whenever they use our app.&lt;/p&gt;

&lt;p&gt;I'll take you through a very simple example of saving a name and username from a form. &lt;/p&gt;

&lt;p&gt;We'll begin with two input fields and a submit button, like so -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhacr8munnkds5mgc9fn.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhacr8munnkds5mgc9fn.jpg" alt="Name and username input fields"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the starting code &lt;a href="https://github.com/LauraToddCode/local-storage-blog/tree/starter-code/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Add onChange and onSubmit event listeners to the input fields and the form as would normally.&lt;/p&gt;

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

&lt;p&gt;In the constructor, initialise the state for 'name' and 'username'.&lt;/p&gt;

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

&lt;p&gt;Then, create the onChange handler functions, allowing them to set the state of 'name' and 'username' to the input values.&lt;/p&gt;

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

&lt;p&gt;Next, create the onSubmit handler function.&lt;/p&gt;

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

&lt;p&gt;In the first line, we use a destructured array to assign this.state.name and this.state.username to the 'name' and 'username' variables. Then, we use the localStorage.setItem() method store those values as 'name' and 'username' to be accessed by the local storage later. &lt;/p&gt;

&lt;p&gt;Make sure that you bind all three functions in the constructor.&lt;/p&gt;

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

&lt;p&gt;Finally, we can use the localStorage.getItem() method within ComponentDidMount() to access the stored values and assign them to this.state.name and this.state.username on initialisation. &lt;/p&gt;

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

&lt;p&gt;That's it! Now, when you enter values into the input fields and refresh the page, those values should remain in the fields.&lt;/p&gt;

&lt;p&gt;You can check your finished code &lt;a href="https://github.com/LauraToddCode/local-storage-blog/tree/main/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>state</category>
      <category>hooks</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Really Simple Intro to Context in React</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 02 May 2021 09:28:53 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-context-in-react-6g1</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-context-in-react-6g1</guid>
      <description>&lt;p&gt;In this post, I'll take you through a simple example of using React's context API to pass information between components.&lt;/p&gt;

&lt;p&gt;Let's say we have a simple app with two components - one is an input (in this case a dropdown menu) and one which displays the result of the input.&lt;/p&gt;

&lt;p&gt;Here's the structure of the app -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd64tk2980o5jz098n58k.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd64tk2980o5jz098n58k.jpg" alt="App structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we want to pass information between the siblings like so -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65g2zhunyr6oquxwpvj5.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65g2zhunyr6oquxwpvj5.jpg" alt="Passing data between siblings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please note:&lt;/strong&gt; In reality, a far simpler way of passing information between siblings is by lifting state. I'm just using this example to keep things simple - you would only really use Context if the structure were more complex and you were having to pass props through a number of components. You can see my post about lifting state &lt;a href="https://dev.to/lauratoddcodes/a-really-simple-intro-to-lifting-state-in-react-1fli"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here's what we're aiming for -&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dtgbi8cwkv48ijgii37.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dtgbi8cwkv48ijgii37.jpg" alt="Final result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The selected item from the dropdown menu appears below in the Result component.&lt;/p&gt;

&lt;p&gt;You can find the starting code &lt;a href="https://github.com/LauraToddCode/using-context/tree/starting-code/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The first thing we want to do is create a new file in our 'src' folder called Context.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipt707l4ksby8s8m52hw.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipt707l4ksby8s8m52hw.jpg" alt="src files"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Context.js file, import React and { createContext }. Then create a variable to contain createContext(). You can call the variable whatever you like but it's standard practice to use the word 'Context' within the name.&lt;/p&gt;

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

&lt;p&gt;Next, create a class component called 'Provider'. Within the provider, we need to initialise the state of the 'season' value. We'll just initialise it to an empty string as it doesn't have a default value.&lt;/p&gt;

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

&lt;p&gt;Then, within the render, we want to return our provider. We do this by adding  tags (if you named your context something different, then use this name for the first part of the tag). Inside the tags, add {this.props.children}.&lt;/p&gt;

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

&lt;p&gt;This class will live at the top level of our application and will store all the data that we want to share with other components. In order to do this, we need to add a value to the &lt;code&gt;&amp;lt;Context.Provider&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;

&lt;p&gt;Within the value, we want to set state to be 'this.state'. Then, we'll add the function that we want to use to handle the change when the user selects an option from the dropdown menu. So, we'll add a handleChange function which sets the state of 'season' to 'event.target.value' (the option selected from the dropdown).&lt;/p&gt;

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

&lt;p&gt;Now, we need to go over to the index.js file and add the Context. &lt;/p&gt;

&lt;p&gt;First, import { Provider } from the Context 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fas5pk6e40vsum7hav0tz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fas5pk6e40vsum7hav0tz.png" alt="import provider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, wrap the App in &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; tags. This will ensure that the entire app has access to data in the Context 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnznnrrgxwfbqzrvxerim.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnznnrrgxwfbqzrvxerim.png" alt="wrap app in provider tags"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, lets go over to our Input.js file and import { Context } from our Context 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp74l4ptt2u4p9likgtzr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp74l4ptt2u4p9likgtzr.png" alt="import context"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, wrap the dropdown menu in &lt;code&gt;&amp;lt;Context.Consumer&amp;gt;&lt;/code&gt; tags. This will allow the dropdown menu to access data from the Context 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fayl1dcs0wm6tcvsgyhsl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fayl1dcs0wm6tcvsgyhsl.png" alt="wrap dropdown in context.consumer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we need to add the handleChange function that we created earlier in the Context file to the dropdown menu. &lt;/p&gt;

&lt;p&gt;To do this, we create an anonymous function with context in the parameters. Then we can add an onChange event listener to the &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; tag and set the value to {context.handleChange}.&lt;/p&gt;

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

&lt;p&gt;Finally, we need to go over to the Result.js file and allow it to access the state of 'season'.&lt;/p&gt;

&lt;p&gt;We need to repeat the same steps we used for the Input.js file of importing { Context }, wrapping the component in &lt;code&gt;&amp;lt;Context.Consumer&amp;gt;&lt;/code&gt; tags and creating an anonymous function.&lt;/p&gt;

&lt;p&gt;This time though, we want to display the current state of 'season'. We do this by adding {context.state.season} within some paragraph 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mnp0qcs5vmvql5v8kvx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mnp0qcs5vmvql5v8kvx.png" alt="add season state to paragraph tags"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! Now when you select an option from the dropdown menu, it should display below.&lt;/p&gt;

&lt;p&gt;You can check your final code &lt;a href="https://github.com/LauraToddCode/using-context/tree/master/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>context</category>
      <category>components</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Really Simple Intro to Lifting State in React</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 25 Apr 2021 11:07:51 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-lifting-state-in-react-1fli</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-lifting-state-in-react-1fli</guid>
      <description>&lt;p&gt;When using React, you can easily share information downwards in the component tree. Using props, you're able to pass data from a parent component to a child component but how do you pass information from a child to a parent or even between siblings?&lt;/p&gt;

&lt;p&gt;That's when we need to lift state. I'll take you through a basic example.&lt;/p&gt;

&lt;p&gt;Lets say you have an App component with two child components. One is a dropdown menu which allows the user to choose their favourite holiday destination and the other is a coloured box which should display the user's choice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwo1bxwq8pkun6zpsguv0.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwo1bxwq8pkun6zpsguv0.jpg" alt="dropdown menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the starting code &lt;span&gt;&lt;a href="https://github.com/LauraToddCode/lifting-state-in-react/tree/main/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;So here's the structure of our app -&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fno5unr6w7o59n1535cc9.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fno5unr6w7o59n1535cc9.jpeg" alt="App structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we want to pass information from Dropdown.js to Chosen.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fly5pho0djlizo5p33omu.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fly5pho0djlizo5p33omu.jpeg" alt="Pass info to sibling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But we can't do that directly, so we need to get the information up to App.js and then down again to Chosen.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ta8hhixxyo8jwhndq0z.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ta8hhixxyo8jwhndq0z.jpeg" alt="Lifting state and passing down again"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way we do this is to set the state in App.js rather than in Dropdown.js. We do this exactly as we would if we were doing it within the child component.&lt;/p&gt;

&lt;p&gt;Begin by initialising the state of the chosen option. You can call it what you like but I'm going to call it 'chosen'.&lt;/p&gt;

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

&lt;p&gt;Next, create an event handler for the onChange event of the dropdown menu. This will set the state of 'chosen' to the chosen value from the dropdown menu -&lt;/p&gt;

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

&lt;p&gt;Don't forget to bind the function in the constructor. So you should have this at the top of your App component -&lt;/p&gt;

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

&lt;p&gt;Now we need to connect the event handler to the Dropdown component so let's go over to the Dropdown.js file and add the onChange property to the &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; tags. We do this by adding "{props.onChoose}". The "onChoose" part an be called anything you like, this will just be what you use as the property name within the App component. &lt;/p&gt;

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

&lt;p&gt;Then we can go back to App.js and add the "onChoose" property to the Dropdown component and set its value to "{this.handleChange}" (the event handler that we set up earlier).&lt;/p&gt;

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

&lt;p&gt;Next, let's go over to the Chosen.js file and "{props.choice}" within some &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tags. This will display the chosen destination.&lt;/p&gt;

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

&lt;p&gt;Finally, go back to the App.js file and add "choice={this.state.chosen}" to the Chosen component. This will mean that whatever the current state of "chosen" is will be displayed in the paragraph tags of the Chosen component.&lt;/p&gt;

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

&lt;p&gt;Now, you can run your app and see your choice displaying in the blue box -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftu8frbxjidn8vfmgc138.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftu8frbxjidn8vfmgc138.jpg" alt="Final result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check your final code &lt;a href="https://github.com/LauraToddCode/lifting-state-in-react/tree/main/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>state</category>
      <category>components</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Really Simple Intro to React Router</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 18 Apr 2021 10:45:28 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-react-router-lod</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-react-router-lod</guid>
      <description>&lt;p&gt;If you want to create a multi-page React app, the easiest way to navigate between pages is by using React Router. In this post I’ll take you through the steps of setting up a navbar for a simple app.&lt;/p&gt;

&lt;p&gt;We’ll start off with three different components which will be three different pages in our app. You can call them whatever you like and put whatever content you like in each component. I’m going to call my components ‘Home’, ‘Products’ and ‘Contact’.&lt;/p&gt;

&lt;p&gt;You can find the starting code &lt;a href="https://github.com/LauraToddCode/using-react-router/tree/starter-code/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To begin, install React Router by typing ‘npm install react-router-dom’ in your terminal.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5nvnsalgyw2o2s31kr8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5nvnsalgyw2o2s31kr8.png" alt="react-router-dom"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once it’s installed, go to your index.js file and import { BrowserRouter } from react-router-dom.&lt;/p&gt;

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

&lt;p&gt;Then wrap the whole app with &lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt; tags so that that every component has access to React Router.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2hp74baeot10sjnt4f8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2hp74baeot10sjnt4f8p.png" alt="Wrap app in Browser Router"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, go over to your App.js file and import { Route } and  { Switch } from react-router-dom.&lt;/p&gt;

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

&lt;p&gt;Now add a Route for each page of your app and wrap them with &lt;code&gt;&amp;lt;Switch&amp;gt;&lt;/code&gt; tags. The path should be the url path for your page and the component property takes in the imported component. The exact property ensures that the route only works if the path used is exactly the same as the given path property.&lt;/p&gt;

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

&lt;p&gt;Now let’s make our navbar by creating a new file called Navbar and adding a functional component as you would normally.&lt;/p&gt;

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

&lt;p&gt;Now import { Link } from react-router-dom.&lt;/p&gt;

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

&lt;p&gt;Add the links to the Navbar using . The to property should match the path you set up for each page in the App component.&lt;/p&gt;

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

&lt;p&gt;Finally, go back to the App.js file, import the Navbar component and add it to the App component.&lt;/p&gt;

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

&lt;p&gt;That’s it! Now when you open your app, you’ll have a Navbar with links to each page.&lt;/p&gt;

&lt;p&gt;You can check your final code &lt;a href="https://github.com/LauraToddCode/using-react-router/blob/master/src/App.js" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>router</category>
      <category>navigation</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Really Simple Intro to Changing Styling Using React State</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 11 Apr 2021 17:41:13 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-changing-styling-using-react-state-f9k</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-changing-styling-using-react-state-f9k</guid>
      <description>&lt;p&gt;When using React, one of the easiest ways to make style changes to an element on an event is by using state.&lt;/p&gt;

&lt;p&gt;In this example, we'll be looking at how we can change the corners of a button from pointed to rounded on click. I know this isn't something you're likely to be doing on a regular basis but it's a nice easy task, just to get to know the concepts.&lt;/p&gt;

&lt;p&gt;From this -&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvc12mx0b6vi2a8a6fv9.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvc12mx0b6vi2a8a6fv9.jpg" alt="Button with pointed corners"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To this - &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdyn09p0r34udbyyxjlg6.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdyn09p0r34udbyyxjlg6.jpg" alt="Button with rounded corners"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To use this method, you'll need to be using a Class Component rather than a Functional Component.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's our starting .js file, with a simple button and some text.&lt;/p&gt;

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

&lt;p&gt;And our starting CSS with some simple styling.&lt;/p&gt;

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

&lt;p&gt;So how do we get it working so that the corners will be rounded when you click the button?&lt;/p&gt;

&lt;p&gt;First, in our .js file, we'll need to add a new state. You can call this whatever you like but I've called it 'pointedCorners' in this example. Currently, the corners of the button are pointed so we can set the state of 'pointedCorners' to true.&lt;/p&gt;

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

&lt;p&gt;Next, below the constructor, we need to add a new method which will handle the click and toggle the state of 'pointedCorners' between true and false depending on what the current state is.&lt;/p&gt;

&lt;p&gt;We'll call our method 'handleClick' for obvious reasons. This checks for the current state of 'pointedCorners' and changes the state to be the opposite.&lt;/p&gt;

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

&lt;p&gt;Be sure to bind your method in the constructor like so -&lt;/p&gt;

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

&lt;p&gt;Binding ensures that 'this' is defined when you call the function.&lt;/p&gt;

&lt;p&gt;We now need to link our method to the button so that the method runs when the button is clicked. Do this by adding {this.handleClick} to the onClick value in your button.&lt;/p&gt;

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

&lt;p&gt;Next, we'll jump over to our CSS file. We need to add two classes which can be applied to the button depending on whether the 'pointedCorners' state is true or false. In this case, we'll add one which sets the corners to be rounded and one that sets the corners to be pointed.&lt;/p&gt;

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

&lt;p&gt;Then we'll jump back over to the .js file. Within the render method, we need to add a new variable. We'll call ours 'toggleBtnClass'. The variable uses a ternary operator to check the current state of 'pointedCorners' and if it's true, the class is set to 'roundedButton', if it's false, the class is set to 'pointedButton'.&lt;/p&gt;

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

&lt;p&gt;Finally, we need to set the className of the button to the 'toggleBtnClass' variable.&lt;/p&gt;

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

&lt;p&gt;You should then have a button that changes when clicked.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;You can find the GitHub repo for this exercise here - &lt;a href="https://github.com/LauraToddCode/Changing-Styling-Using-React-State" rel="noopener noreferrer"&gt;https://github.com/LauraToddCode/Changing-Styling-Using-React-State&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>state</category>
      <category>hooks</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Really Simple Intro to useState in React</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Sun, 04 Apr 2021 16:23:19 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-usestate-in-react-2c7k</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-usestate-in-react-2c7k</guid>
      <description>&lt;p&gt;When it comes to React hooks, useState is one of the most useful. It can be used to capture information that the user inputs and use it elsewhere in your app. &lt;/p&gt;

&lt;p&gt;For example, you could use it to capture the option a user chooses in a dropdown menu or in a series of radio buttons or whether a checkbox is checked or not.&lt;/p&gt;

&lt;p&gt;In this post, I'll take you through getting a user's text from a text input field with useState and displaying 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj77fc9rozj6b95sa9imw.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj77fc9rozj6b95sa9imw.jpg" alt="Final result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, create a new React app and fill it a labelled text input field and some empty paragraph tags, like so -&lt;/p&gt;

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

&lt;p&gt;If you like, you can use the code from my GitHub repo &lt;a href="https://github.com/LauraToddCode/using-usestate/blob/starting-code/src/App.js" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We're going to set the app up so that the user's input will appear in the paragraph tags and will update with every keystroke. We'll therefore use the onChange event listener.&lt;/p&gt;

&lt;p&gt;So, our first step is to add "onChange=" to our input tag. We'll need to add an event handler function to handle that change (which we'll set up in a later step). For now, just add the name of the handler function you intend to make to the input tag, we'll call ours "handleChange".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The naming convention for event handler functions is to use "handle" + "the event" - in this case "handleChange".&lt;/p&gt;

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

&lt;p&gt;Since this post is all about useState, we should probably import it. We do this by adding ", { useState }" after React in the existing import statement for React.&lt;/p&gt;

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

&lt;p&gt;Next, we need to add useState to our code like so -&lt;/p&gt;

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

&lt;p&gt;Let's break that down a little bit. Starting with the right-hand side, useState() can take an argument which will be used as an initial state. So if we wanted to have some text in our paragraph tags to begin with, we could add it to the useState brackets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Would give us this, until we begin typing into the input box -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufcwd2zm2shrol1309qm.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufcwd2zm2shrol1309qm.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this occasion, we don't want to initialise state so we'll just leave it as an empty string within the brackets - useState("").&lt;/p&gt;

&lt;p&gt;Now, let's look at the left-hand side of the statement. useState() gives us an array with two values and uses array destructuring. If you're not familiar with array destructuring, you can take a look at an explanation in the MDN Web Docs &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We've called the values in the array "name" and "setName" but you can call them whatever you like. There is a naming convention of using the same description for both values but with "set" at the beginning of the second value.&lt;/p&gt;

&lt;p&gt;The first item in the array ("name") is going to be what we use to display or otherwise use the value given to use by the user.&lt;/p&gt;

&lt;p&gt;The second item in the array ("setName") is going to be what we use to tell the app where we're getting the information from. We do this within the handler function.&lt;/p&gt;

&lt;p&gt;Let's create that handler function now -&lt;/p&gt;

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

&lt;p&gt;You'll recall that we added an onChange event listener to the input field earlier and gave it a value of "handleChange". Therefore, the input field will call the above function with every keystroke.&lt;/p&gt;

&lt;p&gt;Within the function we have given "setName" (from the useState() function) a value. By using "event.target.value", we assign the user's input text to "name".&lt;/p&gt;

&lt;p&gt;Finally, we can add the "name" value to the paragraph tags and it will update as the user types in the input field.&lt;/p&gt;

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

&lt;p&gt;You can check your code &lt;a href="https://github.com/LauraToddCode/using-usestate/blob/main/src/App.js" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Try and think of other ways that you can use useState() and practice them. The more you do it, the more it will become second nature. You'd be amazed how often this hook can be used in your apps.&lt;/p&gt;

</description>
      <category>react</category>
      <category>state</category>
      <category>hooks</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Really Simple Intro to Using Props in React</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Mon, 29 Mar 2021 13:47:26 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/a-really-simple-intro-to-using-props-in-react-453f</link>
      <guid>https://dev.to/lauratoddcodes/a-really-simple-intro-to-using-props-in-react-453f</guid>
      <description>&lt;p&gt;Props are an incredibly useful tool when working with React so it's worth spending some time getting used to them. Props are a way of sending data down the component tree from a parent to a child component.&lt;/p&gt;

&lt;p&gt;I'll take you through a really simple example of using props to pass the users selection from a list of radio buttons to display in a child component.&lt;/p&gt;

&lt;p&gt;Here's a screenshot of what we're looking to create - the selected name will display in the blue box, which is a child of the App component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facucue6pqrf32b0g9qm9.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facucue6pqrf32b0g9qm9.jpg" alt="final result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Begin by setting up your form like this -&lt;/p&gt;

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

&lt;p&gt;I've added some simple CSS too. You can find all of the starting code &lt;span&gt;&lt;a href="https://github.com/LauraToddCode/using-props-blog/blob/starter-code/src/App.js" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;If you haven't come across React.Fragment before, it's simply a way of wrapping your code without adding unnecessary div tags.&lt;/p&gt;

&lt;p&gt;Now let's use the useState hook to initialise the state of 'value'. Then, create a function which sets the state of 'value' to the value of the selected radio button.&lt;/p&gt;

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

&lt;p&gt;Now we need to add the 'handleChange' function as an onChange event to the form.&lt;/p&gt;

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

&lt;p&gt;Next, let's create the child component in which we want to display our selected name. I've called the component 'Selection' but you can call it whatever you like. The 'Selection' component has a single pair of &lt;code&gt;&amp;lt;h3&amp;gt;&lt;/code&gt; 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fie05irgyj4h70mh8hab4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fie05irgyj4h70mh8hab4.png" alt="Add selection component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Back in the App component, import 'Selection' and add it below your form.&lt;/p&gt;

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

&lt;p&gt;Go back again to your 'Selection' file and add 'props' to the function parameters. This will allow you to pass down information from the parent component.&lt;/p&gt;

&lt;p&gt;Then, within the &lt;code&gt;&amp;lt;h3&amp;gt;&lt;/code&gt; tags add {props.selection}. You can can name the prop whatever you like but I have chosen to call it 'selection'. &lt;/p&gt;

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

&lt;p&gt;Go back to the App component again and within the Selection component, add the 'selection' property (or whatever you've called it).&lt;/p&gt;

&lt;p&gt;We can then assign {value} to it. You'll recall that value holds the state of the currently selected item. By assigning it to the 'selection' property, we have passed it down to the 'Selection' component and the chosen value will now display on the 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjd80gdmidrih66ywplml.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjd80gdmidrih66ywplml.png" alt="add value to selection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check your finished code &lt;a href="https://github.com/LauraToddCode/using-props-blog/tree/master/src" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>props</category>
      <category>components</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Creating a New React App</title>
      <dc:creator>Laura Todd</dc:creator>
      <pubDate>Mon, 22 Mar 2021 16:04:05 +0000</pubDate>
      <link>https://dev.to/lauratoddcodes/creating-a-new-react-app-58p1</link>
      <guid>https://dev.to/lauratoddcodes/creating-a-new-react-app-58p1</guid>
      <description>&lt;p&gt;In this post, I'll be taking you through a simple way to set up a new React App.&lt;/p&gt;

&lt;p&gt;First, you'll need to install Node.js. If you're not sure if you have it you can check using Command Prompt or Terminal.&lt;/p&gt;

&lt;p&gt;If you've never use the Command Prompt or Terminal before, it is an application which will already be installed on your computer. To find it on a PC, go to the start menu and begin typing 'Command Prompt' - it will display in the menu. To find it on a Mac, go to Spotlight and begin typing 'Terminal' - the icon will display.&lt;/p&gt;

&lt;p&gt;To check if you have Node.js type 'node -v' in the terminal and press enter.&lt;/p&gt;

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

&lt;p&gt;If Node is already installed on your machine, the version will be displayed in the line below. &lt;/p&gt;

&lt;p&gt;If you don't have Node installed, you can download it from &lt;a href="https://nodejs.org/en/download/"&gt;here&lt;/a&gt;. Download and install the LTS version. Once you have Node installed, you can create a new app using npm.Back in the Terminal, navigate to the folder in which you want to create your app. If you've not done this in the Terminal before, preface the path with 'cd'. For example, if I wanted to navigate to a folder called GitHub in my Documents folder, I would type 'cd documents/GitHub'.&lt;/p&gt;

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

&lt;p&gt;This will take me to 'C:/Users/laura/Documents/Github.&lt;/p&gt;

&lt;p&gt;Next, type 'npm install -g create-react-app'.&lt;/p&gt;

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

&lt;p&gt;Then, type 'create-react-app my-app'. The 'my-app' part of this command is the name of your app so you can call it whatever you like. Press enter, this may take a couple of minutes while npm creates the files.&lt;/p&gt;

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

&lt;p&gt;Navigate to your new app by typing 'cd my-app' (or whatever you've called your app).&lt;/p&gt;

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

&lt;p&gt;Enter 'npm start'. This will open your app in a local server. &lt;/p&gt;

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

&lt;p&gt;To begin with, it will display the default React App which will look something like this -&lt;/p&gt;

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

&lt;p&gt;Open up the folder holding your app files either in file explorer or in your Text Editor. Go to the 'src' folder - you can delete all of the files in this folder.&lt;/p&gt;

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

&lt;p&gt;In the public folder, you will find an 'index.html' file. You can either keep this file or replace it with your own but it is set up with a root div and has some useful meta tags already set up so I tend to keep it.&lt;/p&gt;

&lt;p&gt;You can then create new a new index.js file in the 'src' folder and begin building your app from there.&lt;/p&gt;

</description>
      <category>react</category>
      <category>commandprompt</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
