Closed jaydenseric closed 3 years ago
I've also got some ideas about a new approach to SSR that could be abstracted into a separate published package:
const { isSSR, rerenderAfter } = useSSR();
if (isSSR && !cacheValue) {
rerenderAfter(load());
return null;
}
I've been working full time on a brand new graphql-react
API and about 80% of the work is complete. It's really taking shape! It's much more intuitive, efficient, has a smaller bundle size, and is user extensible; the cache could potentially be used for more than just GraphQL and loading could potentially be done via custom hooks using something other than fetch
.
Very excited to introduce it some time in the next few weeks, assuming everything works as well as expected in my own apps.
My only concern is that more separate, focused, hooks might result in more renders, but hopefully not.
Currently, the
useGraphQL
React hook does a lot, which is not desirable for a few reasons:Options have a performance cost regardless if they are being used. For example, the
loadOnReset
option utilizes aReact.useCallback
and aReact.useEffect
:https://github.com/jaydenseric/graphql-react/blob/d87d3b3d95930a09922d9c009b47bd78bb2ff488/src/universal/useGraphQL.js#L203-L229
GraphQL
events for their own custom purposes usingReact.useEffect
(e.g. to do something in a callback if cache is reloaded while the component is mounted) they have to reinvent wheels that are already implemented insideuseGraphQL
.I won't be sure of the final design for the hooks without a lot of work that might also depend on some big changes to the
GraphQL
client API as well as the SSR API, but here is one idea: