Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref as content #417

Open
opr-inzn opened this issue Nov 26, 2024 · 3 comments
Open

Ref as content #417

opr-inzn opened this issue Nov 26, 2024 · 3 comments

Comments

@opr-inzn
Copy link

opr-inzn commented Nov 26, 2024

I'm trying to pass a ref as content in my Lenis options:

const ref = useRef<HTMLDivElement>(null)
<Lenis root options={{
            orientation: 'horizontal',
            gestureOrientation: 'both',
            content: ref.current,
        }}
>
   <div ref={ref} className='flex w-max h-full'>

which obviously doesnt work since ref.current might be null until it’s loaded. How can I set a specific content container in React/NextJS?

@clementroche
Copy link
Member

clementroche commented Nov 26, 2024

<Lenis> component is already creating a content element for you, you can access it from ref. I don't see any reason why you would need to define a custom content element.

const contentRef = useRef()

return ( <Lenis ref={(ref)=>{
  contentRef.current = ref?.content
}}>
  // content
</Lenis> )

@opr-inzn
Copy link
Author

opr-inzn commented Nov 26, 2024

Hey @clementroche, thanks for the quick response! I understand. My problem is actually a slightly different one, I just thought it’d be fixed by defining the content.

In my NextJS I have a root layout that uses <Lenis root> for smooth vertical scrolling. I then have a subpage, that is meant to be only scrolled horizontally, so I defined another instance of Lenis in said component, again as root, with the options

orientation: 'horizontal',
gestureOrientation: 'both',

It seems, that the two instances of Lenis interfere with each other and I don’t know how to fix this?

@clementroche
Copy link
Member

clementroche commented Nov 26, 2024

Defining a content element for a root Lenis is useless and will do nothing. Why can't you define a layout that will take care of switching from vertical to horizontal? And then call it within your page? Your Lenis doesn't need to be defined in the root layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants