#Next13 unable to trigger state in parent layout from child component

22 messages · Page 1 of 1 (latest)

silent kite
#

I'm unable to trigger state changes in my parent layout component. I have a side menu for my dashboard pages, and the side menu is a layout file. In one of my pages, i need to be able to hit the TV mode button, which should shut the side menu bar (boolean value) from the child component button, but there's no easy intuitive way to do this. Seems like all i found is something hacky

weary ospreyBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

fleet sedge
silent kite
#

in my layout.jsx, I have this: ``` const [sidebarOpen, setSidebarOpen] = useState(false) <Dialog
as="div"
className="relative z-50 lg:hidden"
onClose={setSidebarOpen}
> <main className="py-10">
<div className="px-4 sm:px-6 lg:px-8">{children}</div>
</main>

#

and in my page.jsx, i have a button when i click it, it should be able to set setSidebarOpen to false. It's simple what i want to do

#

Please provide samples of solutions please

fleet sedge
#

Can you make a minimal reproduction repository so I can clone and try? If you just give snippets then I can only guess and I’d rather not do that

silent kite
#

Yes, let me make a minimal reproduction. codesandbox link work?

fleet sedge
#

Yes

silent kite
#

also, i have a search form. I would like to type in that search form to filter out items in my page.jsx

fleet sedge
fleet sedge
#

Basically, a reproduction repository means a very minimal nextjs without any unrelated bits that shows the problem this post concerns, so that other people can try to fix that problem from the code

silent kite
fleet sedge
#

for this you can use a context provider

silent kite
#

can you provide sample

fleet sedge
#

you can check this

silent kite
#

where do you use the provider? in the layout?

#

thank you