Next.js Discord

Discord Forum

Issue lifting state up to layout.tsx

Answered
Turkish Angora posted this in #help-forum
Open in Discord
Turkish AngoraOP
Hi. Please see the photo of my layout.tsx file. I have implemented a parallax effect using purely CSS. The scroll container for it is inside a component which falls under {children} in layout.tsx.

I want to lift the parallax container's scroll state up from the component in {children}, and pass it to the Navigation component. This is a bit difficult, as the component in question in {children} is not a child of the Navigation component

Any ideas on how I can achieve this? Any help will be greatly appreciated!
Answered by Tonkinese
You'll need to make all of the components reading the state client components, but use React's createContext hook and use the useContext hook where you need to read that state. If you're unfamiliar, that's pretty much like a mini-redux for specific parts of the app.
View full answer

6 Replies

Answer
Tonkinese
You posted it on discord bud, in a public room for people familiar with Next.js
@Tonkinese You posted it on discord bud, in a public room for people familiar with Next.js
Turkish AngoraOP
nah I was wondering because I had lost hope someone would see it, thought it got buried under all the new ones 😂
Tonkinese
lol no worries. I signed up here just to ask someone for help on something else and I'm not having any luck either 😦