How to send setState functions from Root layout down to client components
Answered
Palomino posted this in #help-forum
PalominoOP
My root layout will render an alert component which will have a
message state and a open state. I want my other client components down the tree to be able to change the states of my alert component. How would I do this? I'm thinking of using React's Context API or redux.6 Replies
@Palomino My root layout will render an alert component which will have a `message` state and a `open` state. I want my other client components down the tree to be able to change the states of my alert component. How would I do this? I'm thinking of using React's Context API or redux.
it is better to use context, redux or zustand for that
Answer
@Ray it is better to use context, redux or zustand for that
PalominoOP
Ok just to confirm, I can't do it without context/redux or some other library?
@Palomino Ok just to confirm, I can't do it without context/redux or some other library?
you can't do it on root layout because root layout cannot be client component. so you can't do it without global state
@Ray you can't do it on root layout because root layout cannot be client component. so you can't do it without global state
PalominoOP
What do you mean by
I can make the root layout a client component
root layout cannot be client component without global state?I can make the root layout a client component
@Palomino What do you mean by `root layout cannot be client component without global state`?
I can make the root layout a client component
well the doc said
root layout cannot be client component before but I couldn't find it now, maybe updatedPalominoOP
Thanks anyways, I'm gonna try use context