Running before unmount on server components??
is there a way to wrap a react server component in a function that passes props to it and call something after component is dismounted or something? I know in client components I can make use of useEffect to call stuff before component is dismounted, but not sure how to do the same for server components.
what we basically want to do is:
1. create instance of a thing
2. make it available to the component (could be a hook or props , doesn't matter)
3. make sure that the thing executes a function before the component unmounts
8 Replies
Can't say for sure, but I'd assume that this isn't possible? Server components don't really have a lifecycle that runs on the client, they're pretty much just html
that's my assumption too...
If you need lifecycle stuff, you need client components
And hooks don’t run in RSCs
A hacky solution for a mostly RSC tree could be to add a single client component to a leaf of it that’s basically just a useEffect cleanup
this looks like just a server component wrapped to a client component with an effect cleanup
or maybe as Igor said, this might be writteable as a hoc
F
using wrapper components seems to work btw
Yea donut pattern is the same as a leaf
ah, just got the leaf ideia, it's actually way better