unstable_layout wrapper function
Answered
Croatian Sheepdog posted this in #help-forum
Croatian SheepdogOP
Hi there,
lets say i have
Do i have to call
Thank you in advance!
lets say i have
import { getUser } from './data';
import { unstable_cache } from 'next/cache';
const getCachedUser = unstable_cache(
async (id) => getUser(id),
['my-app-user']
);
export default async function Component({ userID }) {
const user = await getCachedUser(userID);
...
}
Do i have to call
getCachedUser
directly in the component? or can i use it in a wrapper function for example:const getCachedUser = unstable_cache(
async (id) => getUser(id),
['my-app-user']
);
async function getPrettyUser(userID) {
const user = await getCachedUser(userID)
return pretty(user)
}
export default async function Component({ userID }) {
const user = await getPrettyUser(userID);
...
}
Thank you in advance!
Answered by joulev
the wrapper function is fine. you can call the cached function anywhere on the server
3 Replies
@Croatian Sheepdog Hi there,
lets say i have
ts
import { getUser } from './data';
import { unstable_cache } from 'next/cache';
const getCachedUser = unstable_cache(
async (id) => getUser(id),
['my-app-user']
);
export default async function Component({ userID }) {
const user = await getCachedUser(userID);
...
}
Do i have to call `getCachedUser` directly in the component? or can i use it in a wrapper function for example:
ts
const getCachedUser = unstable_cache(
async (id) => getUser(id),
['my-app-user']
);
async function getPrettyUser(userID) {
const user = await getCachedUser(userID)
return pretty(user)
}
export default async function Component({ userID }) {
const user = await getPrettyUser(userID);
...
}
Thank you in advance!
the wrapper function is fine. you can call the cached function anywhere on the server
Answer
Croatian SheepdogOP
thought as much, thank you!
you're welcome