DEV Community

Discussion on: Which React hooks do you use the most?

Collapse
 
lexlohr profile image
Alex Lohr

useRef(initialValue) is just useState({ current: initialValue })[0], so you get that one for free. useCallback(callback, dependencies) is merely a shorthand for useMemo(() => callback, dependencies). Also, you forgot useLayoutEffect in your list.

I mostly use useState, useRef and useEffect. If need be, I'll use useContext, but I try to avoid useCallback (you can directly use a Dispatch from useState as a callback in most occassions and handle the result in an effect). I also mostly refrain from using useReducer, as it is meant to provide an elegant abstraction of complex logic - and one should always simplify logic as much as possible before abstracting it into code.