I currently have a react hook that I'm creating that accepts a query object.
export function useMyQuery(query: QueryObjectType)
{
React.useEffect(executeQuery, [ query ]);
// ...
}
Unfortunately, any time my hook gets called as part of a re-render, despite query
having never changed and still being the exact same object as before, I end up with an infinite loop.
I can resolve this by wrapping query
with JSON.stringify(...)
, however I'm not sure if that's correct? Is there any preferred mechanism for testing equality for objects when being passed as a dependency to useEffect
?