mthanh2209 / react-training

https://react-training-eight.vercel.app
0 stars 0 forks source link

Implement referencing values with refs #155 #178

Closed mthanh2209 closed 8 months ago

mthanh2209 commented 8 months ago
  1. How to add a ref to your component?
    • To add a ref to your component in React, you can use useRef.
  2. How to update a ref’s value?
    • Refs should not be updated directly. Instead, you can use the current property of the ref to change its value.
  3. How refs are different from state?
    • Refs and state are both ways to store and track information, but they serve different purposes.
    • Refs are often used to access DOM elements or to track values that don't cause a re-render.
    • In contrast, state is used to store values that can change and trigger a re-render when they do.
  4. How to use refs safely?
    • When using refs, ensure that you use them safely and avoid updating them directly.
    • Typically, refs are used to reference DOM elements, and instead of changing the value directly, you should use setState to update the state and trigger a re-render.
    • Use refs cautiously to avoid conflicts with how React manages and updates state.
vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-training ❌ Failed (Inspect) Jan 16, 2024 6:58am
storybook ❌ Failed (Inspect) Jan 16, 2024 6:58am