Skip to content

Commit 2a1da81

Browse files
committed
docs: add next 13 documentation
1 parent 8dfa047 commit 2a1da81

File tree

4 files changed

+123
-2
lines changed

4 files changed

+123
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function Component() {
5959
Read the [documentation](https://react-scroll-parallax.damnthat.tv/) for setup and usage instructions.
6060

6161
- [Usage](https://react-scroll-parallax.damnthat.tv/docs/usage/)
62+
- [Usage with NextJS 13](https://react-scroll-parallax.damnthat.tv/docs/usage/next-13)
6263
- [How it works](https://react-scroll-parallax.damnthat.tv/docs/examples/how-it-works)
6364

6465
### Demos

documentation/docs/intro.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function Component() {
6464
## Getting Started
6565

6666
- [Usage](/docs/usage/)
67+
- [Usage with NextJS 13](/docs/usage/next-13)
6768
- [How it works](/docs/examples/how-it-works)
6869

6970
### Demos

documentation/docs/usage/next-13.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Usage with NextJS
2+
3+
This will guide you through a way to setup `react-scroll-parallax` using the [Next 13](https://nextjs.org/blog/next-13) App router.
4+
5+
## Setting Up the ParallaxProvider
6+
7+
[Next 13](https://nextjs.org/blog/next-13) requires client components to be marked with `use-client`, and the `ParallaxProvider` is a client component. In order to use the providers in your app, first create a `providers.tsx` file in the root of the app directory:
8+
9+
```
10+
next-app
11+
└── app/
12+
└── providers.tsx
13+
```
14+
15+
In this file wrap the children in a `<ParallaxProvider>` and mark it as a client component.
16+
17+
:::info
18+
You may add any additional providers you need for your app here in the future.
19+
:::
20+
21+
```tsx
22+
'use client';
23+
24+
import { ParallaxProvider } from 'react-scroll-parallax';
25+
26+
export function Providers({ children }: { children: React.ReactNode }) {
27+
return <ParallaxProvider>{children}</ParallaxProvider>;
28+
}
29+
```
30+
31+
### Add the Providers to the Root Layout
32+
33+
In the `layout.tsx` file at the root of the app directory, import the `Providers` component you just created and wrap it around the children.
34+
35+
```
36+
next-app
37+
└── app/
38+
├── providers.tsx
39+
└── layout.tsx
40+
```
41+
42+
Your layout may differ from the one below — it's is simplified for this example.
43+
44+
```tsx
45+
import { Providers } from './Providers';
46+
47+
export default function RootLayout({
48+
children,
49+
}: {
50+
children: React.ReactNode;
51+
}) {
52+
return (
53+
<html lang="en">
54+
<body>
55+
<Providers>{children}</Providers>
56+
</body>
57+
</html>
58+
);
59+
}
60+
```
61+
62+
## Create a Parallax Effect
63+
64+
Next we can create a simple parallax effect in another client component. Add a `test.tsx` file and place a parallax effect within it. We must also make this as a client component with `use client`.
65+
66+
```
67+
next-app
68+
└── app/
69+
├── providers.tsx
70+
├── layout.tsx
71+
├── test.tsx
72+
└── page.tsx
73+
```
74+
75+
```tsx
76+
'use client';
77+
78+
import { Parallax } from 'react-scroll-parallax';
79+
80+
export default function Test() {
81+
return (
82+
<Parallax scale={[1, 0]}>
83+
<div className="w-48 h-48 bg-red-500" />
84+
</Parallax>
85+
);
86+
}
87+
```
88+
89+
### Use the Parallax within a Page
90+
91+
To add parallax effects to a page, create a `page.tsx` at the route you need. In this example we'll use the homepage so the page exists at the root of the app directory.
92+
93+
```
94+
next-app
95+
└── app/
96+
├── providers.tsx
97+
├── layout.tsx
98+
└── page.tsx
99+
```
100+
101+
Add the `<Test>` component and style the page so it scrolls.
102+
103+
```tsx
104+
import Test from './Test';
105+
106+
export default function Page() {
107+
return (
108+
<main className="flex min-h-[300vh] flex-col items-center justify-between p-24">
109+
<Test />
110+
</main>
111+
);
112+
}
113+
```
114+
115+
That's it. Now that `react-scroll-parallax` is working in your NextJS application you can add your own effects. See more on [how it works](/docs/examples/how-it-works).

documentation/docs/usage/usage.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Usage
22

3-
## First Step
3+
:::info
4+
If you are using Next 13 see this [guide for the NextJS App Router](/docs/usage/next-13)
5+
:::
6+
7+
## Setting Up
48

59
### Wrap with a ParallaxProvider
610

@@ -22,7 +26,7 @@ function App() {
2226

2327
ParallaxProvider component [documentation](/docs/usage/components/parallax-provider).
2428

25-
## Next: Create effects
29+
## Creating effects
2630

2731
After wrapping the app with a provider you can start adding parallax effects.
2832

0 commit comments

Comments
 (0)