<?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: Snap Dragon</title>
    <description>The latest articles on DEV Community by Snap Dragon (@snappdragon).</description>
    <link>https://dev.to/snappdragon</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%2F1012645%2F74deb189-8ea2-4e14-a8ed-190d63010f60.png</url>
      <title>DEV Community: Snap Dragon</title>
      <link>https://dev.to/snappdragon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/snappdragon"/>
    <language>en</language>
    <item>
      <title>What I learned : Immutability as I understand it.</title>
      <dc:creator>Snap Dragon</dc:creator>
      <pubDate>Tue, 07 Feb 2023 07:40:18 +0000</pubDate>
      <link>https://dev.to/snappdragon/what-i-learned-immutability-as-i-understand-it-4aa0</link>
      <guid>https://dev.to/snappdragon/what-i-learned-immutability-as-i-understand-it-4aa0</guid>
      <description>&lt;p&gt;An immutable data type can be defined as one where the data cannot be changed. A new copy of the data type is returned with the altered data instead. Immutability is a very important concept in react. In order to re render a component react checks to see if state has changed by comparing the memory location of the old and new state object. If the memory locations are different , react determines that the state has changed and re renders the component. This is why its extremely important to change the contents of a state object in an immutable way instead of mutating the object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./styles.css";
import {useState} from 'react'

export default function Shelf() {

  const [shelf, setShelf] = useState([]);
  const [book, setBook] = useState("");

  function handleFormSubmit(e){
    e.preventDefault();

    //Update shelf state in an immutable way to trigger 
    // a re render.
    setShelf([...shelf,book]);

  }

  return (

    &amp;lt;&amp;gt;
        &amp;lt;form onSubmit={handleFormSubmit}&amp;gt;
          &amp;lt;label htmlFor="book"&amp;gt;Book: &amp;lt;/label&amp;gt;
            &amp;lt;input type="text" id="book" value={book} onChange={(e)=&amp;gt; setBook(e.target.value)}/&amp;gt;

        &amp;lt;/form&amp;gt;
        &amp;lt;ul className="App"&amp;gt;
          {shelf.map((book,index)=&amp;gt;&amp;lt;li key={index}&amp;gt;{book}&amp;lt;/li&amp;gt;)}
        &amp;lt;/ul&amp;gt;
    &amp;lt;/&amp;gt; 
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>What I learned : Controlled Components</title>
      <dc:creator>Snap Dragon</dc:creator>
      <pubDate>Sat, 04 Feb 2023 10:22:48 +0000</pubDate>
      <link>https://dev.to/snappdragon/what-i-learned-today-controlled-components-3n03</link>
      <guid>https://dev.to/snappdragon/what-i-learned-today-controlled-components-3n03</guid>
      <description>&lt;p&gt;A controlled component is one where the form's data is handled by state. Here are the steps to create a controlled component.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Import the useState hook from the react library.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create the state inside of the component that will handle the form data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the value of the input to the state variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update the state every time in changes.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {useState} from "react";
function App() {
    const [country, setCountry] = useState("");
    return &amp;lt;select value={country} onChange={e =&amp;gt; setCountry(e.target.value)}&amp;gt;
        &amp;lt;option&amp;gt;Country&amp;lt;/option&amp;gt;
        &amp;lt;option value="france"&amp;gt;France&amp;lt;/option&amp;gt;
        &amp;lt;option value="spain"&amp;gt;Spain&amp;lt;/option&amp;gt;
        &amp;lt;option value="germany"&amp;gt;Germany&amp;lt;/option&amp;gt;
    &amp;lt;/select&amp;gt;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>devto</category>
      <category>announcement</category>
      <category>web3</category>
      <category>crypto</category>
    </item>
  </channel>
</rss>
