-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Is your feature request related to a problem? Please describe.
Fetch data in Components without any custom hooks.
Describe the solution you'd like
const apiGetUser = createInterface('GET', '/user/{id}', {swr: true});
const Component = async ({id}) => {
const user = await apiGetUser({id});
return <>{user.name}</>;
}
// or in use hook
const Component = ({id}) => {
const user = use(apiGetUser({id}));
return <>{user.name}</>;
}
// And the above code will first fallback to Suspense then renders.Describe alternatives you've considered
An external utils to wrap api:
const Component = async ({id}) => {
const user = await swr(apiGetUser)({id});
return <>{user.name}</>;
}Additional context
Implemented as experimental_swr first.
Possible Implement
const swr = (asyncFunction) => {
const previousPromiseMap = new Map();
return (params) => {
if (sameParamsHasCalledInShortTimeBefore) {
return previousPromise;
}
return asyncFunction(params);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels