J
J
justifycontent2021-05-17 09:19:40
React
justifycontent, 2021-05-17 09:19:40

Why does useRef need an object?

Hello, I approached the study of hooks, I would like to learn in detail about why the useRef hook needs an object with the current property? I understand that it stores the value there, but I don’t understand why it is in the current property of the object, I know that it kind of saves from overwriting the value during rendering, could you explain this point to me in more detail? I will be very grateful

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twolegs, 2021-05-17
@justifycontent

This is necessary in order to maintain a link to the ref object itself.
That is, `useRef` always returns a reference to the same object.
Thus, it becomes possible to use it without unnecessary updates in the same useEffect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question