DEV Community

Discussion on: React.js Hook questions

Collapse
 
lexlohr profile image
Alex Lohr

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.