Next.js Discord

Discord Forum

Does Next.js has useMemo equivalent for server components

Unanswered
West African Crocodile posted this in #help-forum
Open in Discord
West African CrocodileOP
Does Next.js has useMemo equivalent for server components ?

15 Replies

what is your use case here, useMemo is good if you have useState and other things causing component to re-render - things that server doesnt have

if you just want to cache in general we have react cache and nextjs unstable_cache (former is cache for the same render and other is like fetch cache where it can last for ever)
West African CrocodileOP
I already use unstable_cache but i want to extend caching to include ssr component logic as well
correct if i am wrong but on each page even though apis requests are cached we still have render the components
which in my case i was able to decrease api from 4.2 seconds to 300ms but i believe if was able cache components it would even better
if you have no dynamic, the page can be cached
if you have ppr, you can cache alot more and still have dynamic (ie cookies)
i havent tried, but surely you can unstable_cache components
West African CrocodileOP
how do i pass dynamic values to unstable cache my only problem atm
anyway rendering components unless you are really chaos is so fast - so that shouldnt be your issue
@West African Crocodile how do i pass dynamic values to unstable cache my only problem atm
West African CrocodileOP
what about this ?
im confused on what you want here
West African CrocodileOP
unstable_cache(fn, ["products", tag], config) where tag is dynamic value ?
like when you call the function, you can call it with the dynamic data (ie if userid from cookie)
West African CrocodileOP
I want to pass value id in this case to ['my-app-user', id]
West African CrocodileOP
any idea ?