<?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: yinguzwg-1</title>
    <description>The latest articles on DEV Community by yinguzwg-1 (@yinguzwg1).</description>
    <link>https://dev.to/yinguzwg1</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%2F1781641%2F57170c64-68cc-4584-9f24-4f385f98a0fb.jpeg</url>
      <title>DEV Community: yinguzwg-1</title>
      <link>https://dev.to/yinguzwg1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yinguzwg1"/>
    <language>en</language>
    <item>
      <title>i have quesetions in a Usestate demo</title>
      <dc:creator>yinguzwg-1</dc:creator>
      <pubDate>Mon, 15 Jul 2024 01:09:37 +0000</pubDate>
      <link>https://dev.to/yinguzwg1/i-have-quesetions-in-a-usestate-demo-kpp</link>
      <guid>https://dev.to/yinguzwg1/i-have-quesetions-in-a-usestate-demo-kpp</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./styles.css";
import { useRef, useState } from "react";
export default function App() {
  const [count, setCount] = useState(0);
  const ref = useRef(null);
  const handleClick = () =&amp;gt; {
    setCount(count + 1);
    setCount((pre) =&amp;gt; pre + 1);
  };
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;button onClick={handleClick}&amp;gt;+&amp;lt;/button&amp;gt;
      &amp;lt;h1&amp;gt;{count}&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;Start editing to see some magic happen!&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;demo site as following. &lt;a href="https://codesandbox.io/p/sandbox/affectionate-merkle-nrfkvh?file=%2Fsrc%2FApp.js%3A1%2C1-17%2C2" rel="noopener noreferrer"&gt;https://codesandbox.io/p/sandbox/affectionate-merkle-nrfkvh?file=%2Fsrc%2FApp.js%3A1%2C1-17%2C2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;when i click the button, the count increased two at one time,but when i change code order in the handleClick function, seem like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleClick = () =&amp;gt; {
   setCount((pre) =&amp;gt; pre + 1);
   setCount(count + 1);

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

&lt;/div&gt;



&lt;p&gt;the count increased one at one time.&lt;br&gt;
why?  i hope someone can help me to explain this,thank you&lt;/p&gt;

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