<?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: Ivan García</title>
    <description>The latest articles on DEV Community by Ivan García (@whil).</description>
    <link>https://dev.to/whil</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%2F665916%2F29586154-81ef-42e9-8102-5ea8e1fc6d71.png</url>
      <title>DEV Community: Ivan García</title>
      <link>https://dev.to/whil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/whil"/>
    <language>en</language>
    <item>
      <title>What s useState? </title>
      <dc:creator>Ivan García</dc:creator>
      <pubDate>Tue, 13 Jul 2021 21:12:10 +0000</pubDate>
      <link>https://dev.to/whil/what-s-usestate-69</link>
      <guid>https://dev.to/whil/what-s-usestate-69</guid>
      <description>&lt;p&gt;well is a hook. Which in other words, is a function, which is imported from react&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;but which is your function?&lt;/p&gt;

&lt;p&gt;Help us to controller a state, recive a first param which is the initial state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useState(initialState)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what a the initial state?&lt;br&gt;
It is the value which initiates our state &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; A object useState({}) or Array useState([]) 
 A string useState('whil')
 A number useState(5)
 A Boolean useState(true) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;every time our functional  component Renders. Begins  with the initial state &lt;/p&gt;

&lt;p&gt;But what a return?&lt;br&gt;
Returns us two values. Which is a current  state and a function for update&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, setState] = useState(false)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But which is our current state?&lt;/p&gt;

&lt;p&gt;Well is our initial state which is your current state. Why?&lt;br&gt;
Remember that Provide a initial state. That initial state is our current state during the first rendering&lt;/p&gt;

&lt;p&gt;How update our current state?&lt;/p&gt;

&lt;p&gt;Remember that useState return a function which we can update the current state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setState
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the shape for update our current value is like that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleState = () =&amp;gt;{
  setState(true)
} 
Or
JSX. 
Return(
   &amp;lt;button onClick={() =&amp;gt;setState(true)} &amp;gt; Click Me &amp;lt;/button&amp;gt;
) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because is not called createState?&lt;/p&gt;

&lt;p&gt;Because it wouldn't be right. Because the state Only Be create one-time when our functional component Be render for first time &lt;/p&gt;

&lt;p&gt;setState is not function async. Just calling to enqueueState or enqueueCallback when update and your execution  feels how If it were async &lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Because we shouldn't import react like this </title>
      <dc:creator>Ivan García</dc:creator>
      <pubDate>Mon, 12 Jul 2021 20:27:45 +0000</pubDate>
      <link>https://dev.to/whil/because-we-shouldn-t-import-react-like-this-hf6</link>
      <guid>https://dev.to/whil/because-we-shouldn-t-import-react-like-this-hf6</guid>
      <description>&lt;p&gt;It is very know well the shape how we import react, but however there are issues by doing this&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Yes well works how we want, the problem that exists with the two shape are the  next's&lt;/p&gt;

&lt;p&gt;The first imported&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;What happens? &lt;br&gt;
is that are importing all the Library. And the problem is what we re  making a importing heavy. Which can produce issues for example a low yield.&lt;/p&gt;

&lt;p&gt;The second imported&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' 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens is that we re making same. We re Saying what all the Library Be imported how react&lt;/p&gt;

&lt;p&gt;These complet imports, are inncesary and we re Hurting our development&lt;/p&gt;

&lt;p&gt;So there are a way which Fix these?&lt;/p&gt;

&lt;p&gt;Yes and is import the necessary, how in this example&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;But so. How Compiled our JSX?&lt;/p&gt;

&lt;p&gt;Remember That babel exists and compile our JSX.&lt;br&gt;
In the doc of react, We are told that react JSX is alone sugar for call to react create element&lt;/p&gt;

&lt;p&gt;But We must import createElement?&lt;br&gt;
No. since react use babel which Recognizes our JSX and does not need an import &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
