<?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>
    <anon>TypeScript</anon>
    <anon>JavaScript</anon>
  </categories>
  <description>useStateは初期値に関数を受け取ると、その関数を初期化時に呼び出してそれ以降は初期化処理を行いません。 const [todos, setTodos] = useState(createInitialTodos); // 初期化コストが高い 対してuseRefは関数を受け取って初期化するという機能がありません。 const todos = useRef(createInitialTodos); // ただの関数のrefという扱いになってしまう かといって毎回初期値を生成するのは無駄が大きいです。これを回避する方法を思いついたので紹介です 解決策: 初期値をuseMemoで作る const…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fwww.pandanoir.info%2Fentry%2F2025%2F12%2F15%2F212421&quot; title=&quot;useRefの初期値を1回だけ計算したい - 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>2025-12-15 21:24:21</published>
  <title>useRefの初期値を1回だけ計算したい</title>
  <type>rich</type>
  <url>https://www.pandanoir.info/entry/2025/12/15/212421</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
