<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>akagoma</author_name>
  <author_url>https://blog.hatena.ne.jp/akagoma/</author_url>
  <blog_title>赤ごまヱンヂニアリング</blog_title>
  <blog_url>https://blog.akagoma.com/</blog_url>
  <categories>
    <anon>React</anon>
    <anon>Typescript</anon>
    <anon>node.js</anon>
  </categories>
  <description>見事に引っかかったのでメモ。 TL;DR useState()の値は常に最新とは限らんぞ。 ja.react.dev やりたかったこと useStateでRecord&lt;ID, Record&lt;string, any&gt;&gt;を管理しているときに、onChangeを受けたIDのパラメータだけを変更したかった。 なにがおきた ID=1を更新して、ID=2を更新すると、ID=1が過去データに巻き戻る現象が起きた。 どう対策した useStateの値を使うのではなく、set関数でうまいこと対応した。 詳しいことは「useState 値 反映」とかで調べると仕様が出てくる。</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.akagoma.com%2Fentry%2F2025%2F02%2F17%2Freact-use-state&quot; title=&quot;useState()した値をsetで更新しようとしたら、なぜか古い値で更新されてハマった - 赤ごまヱンヂニアリング&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://cdn-ak.f.st-hatena.com/images/fotolife/a/akagoma/20250217/20250217231459.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2025-02-17 23:30:00</published>
  <title>useState()した値をsetで更新しようとしたら、なぜか古い値で更新されてハマった</title>
  <type>rich</type>
  <url>https://blog.akagoma.com/entry/2025/02/17/react-use-state</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
