4 ms·
> When I build libraries for React, ironically, I don't really use hooks like useState, useReducer, etc. One of the best perks (and footguns) of managing your s
by azangru 4y ago
> When I build libraries for React, ironically, I don't really use hooks like useState, useReducer, etc. One of the best perks (and footguns) of managing your state outside of react is that you get to have full control over when a component should rerender.
I don't understand this quote from Tanner. Aren't React hooks, like, the only way to tell a function React component (while inside of it) to re-render? And if you look at the code of, say, the useBaseQuery hook of tanstack-query, you will indeed find React's native hooks being used there [0].
0 - https://github.com/TanStack/query/blob/main/packages/react-query/src/useBaseQuery.ts https://github.com/TanStack/query/blob/main/packages/react-q...
- pcthrowaway 4y agoI really only have familiarity with React-query, but I'd guess it's something like: While of course React-query plugs into the React lifecycle, it's also kind of an escape hatch that plays nice with React. Managing the fetch function calls, their state, their resolutions, and the cache, all probably happens outside of React, but then changes to any of the query state are reflected into the React lifecycle. This probably lets him do something like using localstorage for storing cached query data, communicating between tabs, etc