# React Scroll Parallax > React hooks and components for scroll-driven parallax effects via WAAPI (v4 beta). This file contains all documentation content in a single document following the llmstxt.org standard. ## Hooks All provided React hooks. ```ts import { useParallax } from 'react-scroll-parallax'; import { useParallaxController } from 'react-scroll-parallax'; ``` ## Documentation - [`useParallax()`](/docs/v4/usage/hooks/use-parallax) - [`useParallaxController()`](/docs/v4/usage/hooks/use-parallax-controller) --- ## useParallaxController This hook provides you access to the [`ParallaxController`](https://parallax-controller.vercel.app/docs/api/parallax-controller/) via [React context](https://facebook.github.io/react/docs/context.html). The hook must be called in a component rendered within the [``](/docs/v4/usage/components/parallax-provider). The most common usage of the controller is to update cache if the page layout has changed. ```tsx import { useParallaxController } from 'react-scroll-parallax'; ``` ## Examples The following are some common scenarios that occur where you may need to access and update the controller. ### Usage For Images Updating the `ParallaxController` cache once an image loads: ```tsx function Image(props) { const parallaxController = useParallaxController(); // updates cached values after image dimensions have loaded const handleLoad = () => parallaxController.update(); return ; } ``` ### Example Route Change Hook Another common use case is the need to update cache after a route changes. This custom hook updates the controller each time the location changes. ```tsx function useUpdateControllerOnRouteChange() { const location = useLocation(); const parallaxController = useParallaxController(); useEffect(() => { parallaxController.update(); }, [location.pathname]); } ``` ### Parallax Controller See the `parallax-controller` [documentation](https://parallax-controller.vercel.app/docs/api/parallax-controller/) of all the methods that can be called from the controller --- ## useParallax Main hook for applying parallax effects to a DOM element. Any of the documented [effects and configurations](/docs/v4/usage/parallax-props) can be passed as params to the hook. ```tsx import { useParallax } from 'react-scroll-parallax'; ``` ## Example To use the hook assign the `ref` returned to the element that you would like to apply effects to. Then provide the hook with the [prop configuration](/docs/v4/usage/parallax-props) for the effects you need. ```tsx function Component() { const { ref } = useParallax({ speed: 10 }); return ; } ``` ### Returned Values The `useParallax()` hook returns the following: | Name | Description | | -------------- | -------------------------------------------------------------------------------------------------------------------------- | | **ref** | `ref` that must be assigned to a DOM element | | **controller** | The [`ParallaxController`](https://parallax-controller.vercel.app/docs/api/parallax-controller/) instance. | | **element** | The `Element` created by the [`ParallaxController`](https://parallax-controller.vercel.app/docs/api/parallax-controller/). | --- ## Components All provided React components. ```ts import { Parallax } from 'react-scroll-parallax'; import { ParallaxBanner } from 'react-scroll-parallax'; import { ParallaxProvider } from 'react-scroll-parallax'; ``` ## Documentation - [``](/docs/v4/usage/components/parallax-component) - [``](/docs/v4/usage/components/parallax-banner-component) - [``](/docs/v4/usage/components/parallax-provider) --- ## ParallaxBanner Component that sets up layers of `useParallax` elements to achieve a parallaxing banner. Enables the layering of images, or custom markup, with scroll effects in a container that hides overflow. ```tsx import { ParallaxBanner, ParallaxBannerLayer } from 'react-scroll-parallax'; ``` ### Working Demos See some example [code with demos](/docs/v4/examples/banners). ## Examples There are two ways to setup a banner: 1. You can use the `` [`layers`](#with-the-layers-prop) prop. 2. You can define [`ParallaxBannerLayer`](#example-with-the-parallaxbannerlayer) as the `` children. ### Example with the ParallaxBannerLayer Use the `ParallaxBannerLayer` component to define the `speed` and `image` for your banner. In this case, it will create a banner using a single image, that moves slower than the rate of scroll, and the edges of the image will never be visible. ```jsx ``` ### Example with the layers prop Use the `layers` to supply a `speed` and `image` to your banner. In this case, it will create a banner using a single image, that moves slower than the rate of scroll, and the edges of the image will never be visible. ```jsx ``` :::caution You **must** define a style that gives the root `` a `height` value otherwise the banner will have no height and be hidden. This can be through a `style`, through a `className`, or other method of styling. ::: ### Creating Multiple Layers Define multiple Banner layer children with independent prop configurations. ```jsx ``` Supply the `layers` prop with additional configuration for more images. Each layer can contain unique configurations. ```jsx ``` :::caution **Layer order matters.** First element in the the array or children will appear on the bottom of the stacking context; last layer of the array or children will appear on top. ::: ### Custom Layer Markup This example defines a headline in the second layer. ```jsx My Headline ``` You can also pass your own markup or components to the `children` property when using `layers`. ```jsx ``` ### Using a Custom Image Element You don't need to use the `image` prop and can instead pass your own `img`, `picture`, `video` or custom image component. Use this if you need to use accessible images, custom image components, or other `img` attributes like `srcSet` or `loading`. ```jsx ``` ## Props The following are all props that can be passed to the `` component: | Name | Type | Description | | ------------ | :--------------: | -------------------------------------------------------------------------------------------------------------------------- | | **disabled** | `boolean` | Disables _all_ parallax layers when enabled. | | **layers** | `array` | Optional `array` of layers -- [see layer props below](/docs/v4/usage/components/parallax-banner-component#banner-layers-prop) | | `...rest` | `HTMLDivElement` | All other properties are spread to the ``. | :::info All other props are defined on the root `div` element. ```jsx ``` ::: ## Banner Layer Props The `ParallaxBannerLayer` the following configuration as props. The `layers` prop takes an array of objects that represent each image (or custom children) of the parallax banner. The following properties describe a layer object: | Name | Type | Default | Description | | ------------ | :---------------------: | :------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **children** | `ReactElement` | | Custom layer children provided as a React element, for example `