DEV Community

Agata
Agata

Posted on

1

React.useRefの理解を含めるエクササイズ

document.getElementById vs useRef vs useState

違いはわかりますか…?
いつ使えばいいか迷ったら、ぜひ下記のエクササイズをやってみてください!

エクササイズはこちらです:

https://codesandbox.io/s/react-useref-t7pmkn?file=/read.me

プロジェクトでは4つエクササイズがあります:

  • エクササイズ1:src/components/Zero.tsx (document.getElementById vs useState)
  • エクササイズ2:src/components/First.tsx (document.getElementById vs useRef)
  • エクササイズ3:src/components/Second.tsx (useRef vs useState:useRefを使いすぎた場合)
  • エクササイズ4:src/components/Third.tsx (useRef vs useState:不要なレンダリング防ぎ方)

read.meを参考にしてください。

回答はこちらになります:

https://codesandbox.io/s/react-hooks-good-answers-6mhjcz?file=/read.me

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please show some love ❤️ or share a kind word in the comments if you found this useful!

Got it!