lenis/react
April 3, 2026 · View on GitHub
Introduction
lenis/react provides a <ReactLenis> component that creates a Lenis instance and provides it to its children via context. This allows you to use Lenis in your React app without worrying about passing the instance down through props. It also provides a useLenis hook that allows you to access the Lenis instance from any component in your app.
Installation
npm i lenis
Recommended CSS
Import the Lenis CSS to ensure proper behavior:
import 'lenis/dist/lenis.css'
Usage
Basic
import { ReactLenis, useLenis } from 'lenis/react'
function App() {
const lenis = useLenis((lenis) => {
// called every scroll
console.log(lenis)
})
return (
<>
<ReactLenis root />
{ /* content */ }
</>
)
}
Props
options: Lenis options.root: Whentrue, makes the Lenis instance globally accessible viauseLenisfrom anywhere in your app (even outside the provider tree). Lenis will use the default<html>scroll container. When'asChild', renders wrapper elements for custom scroll containers while still making the instance globally accessible. Default:false.
Hooks
Once the Lenis context is set (components mounted inside <ReactLenis>) you can use these handy hooks:
useLenis is a hook that returns the Lenis instance
The hook takes three arguments:
callback: The function to be called whenever a scroll event is emitteddeps: Trigger callback on changepriority: Manage callback execution order
Examples
Custom requestAnimationFrame loop:
import { ReactLenis } from 'lenis/react'
import { useEffect, useRef } from 'react'
function App() {
const lenisRef = useRef()
useEffect(() => {
function update(time) {
lenisRef.current?.lenis?.raf(time)
}
const rafId = requestAnimationFrame(update)
return () => cancelAnimationFrame(rafId)
}, [])
return (
<ReactLenis root options={{ autoRaf: false }} ref={lenisRef} />
)
}
GSAP integration
import gsap from 'gsap'
import { ReactLenis } from 'lenis/react'
import { useEffect, useRef } from 'react'
function App() {
const lenisRef = useRef()
useEffect(() => {
function update(time) {
lenisRef.current?.lenis?.raf(time * 1000)
}
gsap.ticker.add(update)
return () => gsap.ticker.remove(update)
}, [])
return (
<ReactLenis root options={{ autoRaf: false }} ref={lenisRef} />
)
}
Framer Motion integration:
import { ReactLenis } from 'lenis/react';
import type { LenisRef } from 'lenis/react';
import { cancelFrame, frame } from 'framer-motion';
import { useEffect, useRef } from 'react';
function App() {
const lenisRef = useRef<LenisRef>(null)
useEffect(() => {
function update(data: { timestamp: number }) {
const time = data.timestamp
lenisRef.current?.lenis?.raf(time)
}
frame.update(update, true)
return () => cancelFrame(update)
}, [])
return (
<ReactLenis root options={{ autoRaf: false }} ref={lenisRef} />
)
}
lenis/react in use
- @darkroom.engineering/satus Our starter kit.
License
MIT © darkroom.engineering