Questions and answers
Here are some questions and answers to refresh your knowledge:
- What is a ref?
A React ref is a container to hold a persistent value. In general, you can use the value as a raw state with no update capability.
- What is
useRef
?A
useRef
hook can be used to create a ref in a function component. Once created, it can be used as a persistent container during the life cycle of the component. - What are the common usages of
useRef
?One major usage of
useRef
is to hold a DOM instance that can be used to invoke native DOM functionalities. Another major usage ofuseRef
is to sneak behind React to do something without kicking off the engine accidentally.