<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>panda_noir</author_name>
  <author_url>https://blog.hatena.ne.jp/panda_noir/</author_url>
  <blog_title>Panda Noir</blog_title>
  <blog_url>https://www.pandanoir.info/</blog_url>
  <categories>
    <anon>React</anon>
    <anon>React hooks</anon>
  </categories>
  <description>小技。 「一時的な変数を useRef で定義したい」といった時に便利なテクニックです。 { const prevValue = useRef(value); useEffect(() =&gt; { if (prevValue.current === value) return; // 変化したタイミングで行う処理 prevValue.current = value; }, [value]); } やり方は簡単です。↑こうやってブロック({})で囲むだけです。コレで prevValue のスコープを狭められます。フックのルールにも抵触しません。 値の変化を検知して副作用を実行したいときに僕はよくこ…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fwww.pandanoir.info%2Fentry%2F2023%2F02%2F14%2F191212&quot; title=&quot;ブロックを使うと prevValue を使うフックが書きやすい - Panda Noir&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></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2023-02-14 19:12:12</published>
  <title>ブロックを使うと prevValue を使うフックが書きやすい</title>
  <type>rich</type>
  <url>https://www.pandanoir.info/entry/2023/02/14/191212</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
