Issue lifting state up to layout.tsx
Answered
Turkish Angora posted this in #help-forum
Turkish AngoraOP
Hi. Please see the photo of my
I want to lift the parallax container's scroll state up from the component in
Any ideas on how I can achieve this? Any help will be greatly appreciated!
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 componentAny 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.6 Replies
@Turkish Angora 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!
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.Answer
@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.
Turkish AngoraOP
Thanks! Will try
How did you find this question btw, just curious
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 😦