Skip to content

Instantly share code, notes, and snippets.

@oney
Last active July 3, 2022 01:01
Show Gist options
  • Save oney/cccdb1b6ccd241dbefb327a77d24aa56 to your computer and use it in GitHub Desktop.
Save oney/cccdb1b6ccd241dbefb327a77d24aa56 to your computer and use it in GitHub Desktop.
function usePrefetch() {
return useQuery("A", () => fetchA());
}
function InnerA({isLoading, data}: ReturnType<typeof usePrefetch>) {
useEffect(() => {
if (data) sendEvent('fetchA', data);
}, [data]);
if (isLoading) return <p>Loading</p>;
return <div> {data} <B /> </div>;
}
function A() {
const inner = <InnerA {...usePrefetch()} />;
return useIsPrefetch() ? <B /> : inner;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment