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
Update: after discussion we can actually both respect the rules of hooks and reduce the boiler plate, by simply considering the enableWebsocket && websocketClient from within the deepest hook itself instead of at configuration or call time. Since we can capture the configuration value from within the closure of the hook function, there is no need for additional checks at call site.
I.e.
// this is wrongconstwsHooks=enableWebsocket&&websocketClient ? configureFooHooks() : undefined;useFoo(){wsHooks?.useFooUpdates()// <-- ! rules of hooks}configureFooHooks(){return{useFooUpdates: ()=>{ ... implementation}}}// this is verboseconst{ useFooUpdates }=configureFooHooks()useFoo(){useFooUpdates()}configureFooHooks(client){if(!client)return{useFooUpdates: ()=>{/* no-op hook */}}elsereturn{useFooUpdates: ()=>{ ... implementation}}}// this is correctconst{ useFooUpdates }=configureFooHooks()useFoo(){useFooUpdates()}configureFooHooks(client){return{useFooUpdates(){// <-- single definitionuseEffect(){if(!client||!wsEnabled)return;// <-- call stack is preserved so no rules of hooks violationelse// ... implementation}
...
}}}
Update: after discussion we can actually both respect the rules of hooks and reduce the boiler plate, by simply considering the
enableWebsocket && websocketClient
from within the deepest hook itself instead of at configuration or call time. Since we can capture the configuration value from within the closure of the hook function, there is no need for additional checks at call site.I.e.
Originally posted by @dialexo in graasp/graasp-apps-query-client#142 (comment)
The text was updated successfully, but these errors were encountered: