You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of parameter one, we can pass a read function, which:
reads the fragment reference (this can be done imperatively with no problem), and
registers the fact that this fragment was read. Then, after we call the resolver, we can call useEffect, e.g.:
constfragmentsRead=[];functionread(fragment){fragmentsRead.push(fragment);returnreadFragmentData(fragment);}constjsxResult=readerWithRefetchQueries.readerArtifact.resolver({
data,parameters: fragmentReference.variables,
read,},additionalRuntimeProps,);useEffect(()=>{// subscribe to each fragment read});returnjsxResult;
Wowzers! We did it! We defeated the fish-grabbin' rules of hooks.
Alternative solution:
Alternatively, read can be imported, or a fragment has a .read method (I am partial to this), and calling read/.read pushes the fragment onto an array held in some context.
This context is provided in a component that specifically wraps the component we created in componentCache, e.g.:
fragmentReference.read()
would be so nice! You can do it conditionally! You can do it in a loop! Rules of hooks are annoying!But how? Reading a fragment reference creates subscriptions in
useEffect
. Alas, we are foiled. It cannot be done. We must give upSketch of solution
But wait! We have a secret weapon, the fact that we can do whatever we want in componentCache. A sketch of a solution might look like:
As part of parameter one, we can pass a
read
function, which:useEffect
, e.g.:Wowzers! We did it! We defeated the fish-grabbin' rules of hooks.
Alternative solution:
read
can be imported, or a fragment has a.read
method (I am partial to this), and callingread
/.read
pushes the fragment onto an array held in some context.read
is only called during the render of a component with this context.The text was updated successfully, but these errors were encountered: