<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ahmed Ewees Korany</title>
    <description>The latest articles on Forem by Ahmed Ewees Korany (@ahmedeweeskorany).</description>
    <link>https://forem.com/ahmedeweeskorany</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%2F1319886%2Fb02431cf-2258-44e2-8152-182052a49e77.jpeg</url>
      <title>Forem: Ahmed Ewees Korany</title>
      <link>https://forem.com/ahmedeweeskorany</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ahmedeweeskorany"/>
    <language>en</language>
    <item>
      <title>Changing State After Defining it using Const ??!! What Is Going On?</title>
      <dc:creator>Ahmed Ewees Korany</dc:creator>
      <pubDate>Mon, 24 Jun 2024 06:40:05 +0000</pubDate>
      <link>https://forem.com/ahmedeweeskorany/changing-state-after-defining-it-using-const-what-is-going-on-3j0i</link>
      <guid>https://forem.com/ahmedeweeskorany/changing-state-after-defining-it-using-const-what-is-going-on-3j0i</guid>
      <description>&lt;p&gt;Have you asked yourself how you can change the state you defined in spite of using const declarations like &lt;code&gt;const [count,setCount] = useState(0)&lt;/code&gt;? let's dive a little bit ... &lt;/p&gt;

&lt;h4&gt;
  
  
  The first question we need to ask is that does the const declarations make variables immutable.
&lt;/h4&gt;

&lt;p&gt;actually, const creates something called &lt;code&gt;constant reference to the value&lt;/code&gt; which states that you can't change the reference of the variable but if you have an object or array you can easily edit it. so the real answer to the previous question is &lt;code&gt;No&lt;/code&gt;. Now let's back to our main topic:&lt;br&gt;
we have received two variables from useState hook &lt;code&gt;(by Destructuring)&lt;/code&gt; so according to the above content we can't edit on &lt;code&gt;count&lt;/code&gt; variable, can we? &lt;/p&gt;

&lt;p&gt;the answer is that we can't edit on &lt;code&gt;count&lt;/code&gt; variable directly without using &lt;code&gt;setCount&lt;/code&gt; and if you try to do that, you'll receive a Type Error indicating that count is a constant variable as shown in the main image.&lt;/p&gt;

&lt;p&gt;so, what is the magic that &lt;code&gt;setCount&lt;/code&gt; is making ?&lt;br&gt;
well, &lt;code&gt;setCount&lt;/code&gt; is a function provided by reacting and using its mechanisms like (virtual DOM..etc) to change the value of &lt;code&gt;count&lt;/code&gt; variable.&lt;/p&gt;

&lt;h4&gt;
  
  
  thank you for reaching this point.
&lt;/h4&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
