Hello, Dev Community.
I am a new developer who wants to learn React.js.
I want to know about useContext, and useRef.
How & When can I use this hooks in React?
For further actions, you may consider blocking this person and/or reporting abuse
Hello, Dev Community.
I am a new developer who wants to learn React.js.
I want to know about useContext, and useRef.
How & When can I use this hooks in React?
For further actions, you may consider blocking this person and/or reporting abuse
Plain -
Prajesh Gawhale -
Henrique Emanoel Viana -
Gabriel -
Top comments (1)
useContext is a way to transfer state data from somewhere up in the component tree to any component inside it; its use is to avoid prop drilling, which means that you carry the state as props through every component from the parent to the grand-grand-grand-child that requires it.
useRef is basically a useState without the setter; you get a memoized object. While you usually only use its current-property, you could do whatever you like with it (but in this case, be sure to document it). You can use it to create a ref used by the component to access the rendered DOM node, or a way to carry state without the reconciler ever noticing a difference.