Skip to content

Instantly share code, notes, and snippets.

@arackaf
Last active November 26, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arackaf/366348066ea920a55f6f95fb2e78998d to your computer and use it in GitHub Desktop.
Save arackaf/366348066ea920a55f6f95fb2e78998d to your computer and use it in GitHub Desktop.
const useSuspenseQuery = options => {
const [resource] = useState(() => new DataQueryingThingWithState());
resource.readLatest(options); //will throw a promise if not ready
useEffect(() => {
return () => resource.current.dispose(); //never call in the side rendering / "parallel universe" tree :(
}, []);
return resource.current.state; // or whatever
};
@skclusive
Copy link

i guess as the throw happens before useEffect, the callback might have not registered.

const useSuspenseQuery = options => {
  const resource = useRef(new DataQueryingThingWithState());
  
// before the throw
  useEffect(() => {
    return () => resource.current.dispose(); //never call in the side rendering / "parallel universe" tree :(
  }, []);

  resource.readLatest(options); //will throw a promise if not ready
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment