Last active
July 3, 2022 01:01
-
-
Save oney/cccdb1b6ccd241dbefb327a77d24aa56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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