Skip to content

Commit bf2572d

Browse files
committed
docs: docs for useParallax hook
1 parent a0f67ad commit bf2572d

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,23 @@ yarn add react-scroll-parallax
3838
## Documentation
3939

4040
- [Example Usage](#usage)
41+
- [Optimizations to Reduce Jank](#optimizations-to-reduce-jank)
42+
43+
### Docs: Components
44+
4145
- [`<Parallax>`](/docs/parallax-component.md)
4246
- [`<ParallaxBanner>`](/docs/parallax-banner-component.md)
4347
- [`<ParallaxProvider>`](/docs/parallax-provider-component.md)
44-
- [Optimizations to Reduce Jank](#optimizations-to-reduce-jank)
45-
- [PSA](#psa)
48+
49+
### Docs: Hooks
50+
51+
- [`useParallax()`](/docs/use-parallax-hook.md)
52+
- [`useController()`](/#todo)
53+
- [`useParallaxImage`](/#todo)
4654

4755
## Usage
4856

49-
### Wrap with a ParallaxProvider
57+
### First: Wrap with a ParallaxProvider
5058

5159
The [`<ParallaxProvider>`](#parallaxprovider) must wrap the component tree that contains all `<Parallax>` components. This should be a top level component like `<App>`. For example:
5260

@@ -64,7 +72,7 @@ function App() {
6472
}
6573
```
6674

67-
### Create effects with useParallax()
75+
### Then: Create effects with useParallax()
6876

6977
Then import the `useParallax` hook and use it anywhere within the provider. Here's an example that uses the `speed` prop so simply speed up (or slowdown) the rate of scroll.
7078

@@ -77,7 +85,7 @@ const Component = () => {
7785
};
7886
```
7987

80-
### Create effects with \<Parallax>
88+
### Or: Create effects with \<Parallax>
8189

8290
You can also use the `Parallax` component. Here's an example that will transform the element on the `translateY` axis starting at `-20%` and ending at `20%` (`translateY = [-20, 20]` \*percent is assumed with no provided unit).
8391

docs/use-parallax-hook.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Hook useParallax()
2+
3+
## Example Usage
4+
5+
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](https://parallax-controller.vercel.app/docs/usage/props) for the effects you need.
6+
7+
```tsx
8+
import { useParallax } from 'react-scroll-parallax';
9+
10+
function Component() {
11+
const props = { speed: 10 };
12+
const { ref } = useParallax<HTMLDivElement>(props);
13+
return <div ref={ref} />;
14+
}
15+
```
16+
17+
### Returned Values
18+
19+
The `useParallax()` hook returns the following:
20+
21+
| Name | Description |
22+
| -------------- | -------------------------------------------------------------------------------------------------------------------------- |
23+
| **ref** | `ref` that must be assigned to a DOM element |
24+
| **controller** | The [`ParallaxController`](https://parallax-controller.vercel.app/docs/api/parallax-controller/) instance. |
25+
| **element** | The `Element` created by the [`ParallaxController`](https://parallax-controller.vercel.app/docs/api/parallax-controller/). |

0 commit comments

Comments
 (0)