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
#Next13 unable to trigger state in parent layout from child component
22 messages · Page 1 of 1 (latest)
🔎 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)
Can you give us some minimal code to illustrate current behaviour and what you want to have?
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
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
Yes, let me make a minimal reproduction. codesandbox link work?
Yes
@fleet sedge will this work: https://codesandbox.io/p/sandbox/inspiring-brattain-tlgq32?file=%2Fapp%2Flayout.tsx%3A94%2C1
also, i have a search form. I would like to type in that search form to filter out items in my page.jsx
Can you simplify the layout? Since this problem doesn’t concern css it would be best to remove any styling and animation. Helpers here might not have the time and willpower to parse 300+ lines in a question
And add this in there too
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
okay, look now: https://codesandbox.io/p/sandbox/inspiring-brattain-tlgq32?file=%2Fapp%2Flayout.tsx%3A17%2C8. All i want to do, it to toggle the value for sidebarOpen, in the page.tsx file with the button tag
ok so i finally get back to my laptop
for this you can use a context provider
can you provide sample