Created
December 29, 2021 02:23
-
-
Save 0916dhkim/2817d3e387cde5f09976653f2a0d1499 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Original | |
export function useServerResponse(location) { | |
const key = JSON.stringify(location); | |
const cache = unstable_getCacheForType(createResponseCache); | |
let response = cache.get(key); | |
if (response) { | |
return response; | |
} | |
response = createFromFetch( | |
fetch('/react?location=' + encodeURIComponent(key)) | |
); | |
cache.set(key, response); | |
return response; | |
} | |
// Request different route depending on window URL. | |
export function useServerResponse() { | |
const {pathname} = useLocation(); | |
const cache = unstable_getCacheForType(createResponseCache); | |
let response = cache.get(pathname); | |
if (response) { | |
return response; | |
} | |
response = createFromFetch(fetch(`/react${pathname}`)); | |
cache.set(pathname, response); | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment