0.0.47 • Published 1 month ago

@studio-freight/react-lenis v0.0.47

Weekly downloads
-
License
-
Repository
github
Last release
1 month ago

NPM Version NPM Downloads

Introduction

react-lenis 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 @studio-freight/react-lenis

Usage

Basic

import { ReactLenis, useLenis } from '@studio-freight/react-lenis'

function Layout() {
  const lenis = useLenis(({ scroll }) => {
    // called every scroll
  })

  return (
    <ReactLenis root>
      { /* content */ }
    </ReactLenis>
  )
}

RSC

// libs/react-lenis.js

'use client'

export * from '@studio-freight/react-lenis'
import { ReactLenis, useLenis } from 'libs/react-lenis'

Props

  • options: Lenis options.
  • root: Lenis will be instanciate using <html> scroll. Default: false.
  • autoRaf: if false, lenis.raf needs to be called manually. Default: true.
  • rafPriority: Tempus execution priority. Default: 0.
  • className: Class name for the wrapper div. Default: ''.

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 argument:

  • callback: The function to be called whenever a scroll event is emitted
  • deps: Trigger callback on change
  • priority: Manage callback execution order

Examples

GSAP integration

function Component() {
  const lenisRef = useRef()
  
  useEffect(() => {
    function update(time) {
      lenisRef.current?.lenis?.raf(time * 1000)
    }
  
    gsap.ticker.add(update)
  
    return () => {
      gsap.ticker.remove(update)
    }
  })
  
  return (
    <ReactLenis ref={lenisRef} autoRaf={false}>
      { /* content */ }
    </ReactLenis>
  )
}

@studio-freight/react-lenis in use

Authors

This tool is maintained by the darkroom.engineering team:

License

The MIT License.

0.0.47

1 month ago

0.0.46

2 months ago

0.0.46-dev.1

2 months ago

0.0.46-dev.0

2 months ago

0.0.45

3 months ago

0.0.44

3 months ago

0.0.44-dev.3

3 months ago

0.0.44-dev.2

3 months ago

0.0.44-dev.1

3 months ago

0.0.44-dev.0

4 months ago

0.0.42

4 months ago

0.0.43

4 months ago

0.0.40

4 months ago

0.0.39

5 months ago

0.0.22

10 months ago

0.0.23

10 months ago

0.0.24

10 months ago

0.0.25

10 months ago

0.0.37

6 months ago

0.0.38

6 months ago

0.0.30

8 months ago

0.0.32

8 months ago

0.0.33

8 months ago

0.0.34

8 months ago

0.0.35

8 months ago

0.0.36

8 months ago

0.0.26

9 months ago

0.0.27

8 months ago

0.0.28

8 months ago

0.0.29

8 months ago

0.0.21

11 months ago

0.0.20

12 months ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.11

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago