@@ -7,19 +7,80 @@ export const meta = [
7
7
},
8
8
];
9
9
10
- ## Hello
10
+ # Usage with Next.js
11
11
12
- ``` jsx
13
- import { useState } from ' react' ;
12
+ How to use the library with [ Next.js ** /app** router] ( https://nextjs.org/docs ) (also is compatible with ** /pages** router).
14
13
15
- export default function Counter () {
16
- const [count , setCount ] = useState (0 );
14
+ 1 . Create a new Next.js project:
17
15
16
+ ``` bash
17
+ npx create-next-app@latest
18
+ ```
19
+
20
+ 2 . Select the default options:
21
+
22
+ ``` bash
23
+ √ What is your project named? ... nextjs-project
24
+ √ Would you like to use TypeScript? ... Yes
25
+ √ Would you like to use ESLint? ... Yes
26
+ √ Would you like to use Tailwind CSS? ... Yes (👈 optional)
27
+ √ Would you like to use ` src/` directory? ... Yes (👈 optional)
28
+ √ Would you like to use App Router? (recommended) ... Yes
29
+ √ Would you like to customize the default import alias (@/* )? ... No
30
+ ```
31
+
32
+ 3 . Install the library:
33
+
34
+ ``` bash
35
+ npm install @pheralb/toast
36
+ ```
37
+
38
+ 4 . Add the [ ` ToastProvider ` ] ( /provider ) to the ` layout.tsx ` file:
39
+
40
+ > 💡 By default, ` ToastProvider ` includes ` use client ` directive.
41
+
42
+ ``` tsx
43
+ // 📃 layout.tsx
44
+ import { ToastProvider } from ' @pheralb/toast' ;
45
+
46
+ export default function RootLayout({
47
+ children ,
48
+ }: Readonly <{
49
+ children: React .ReactNode ;
50
+ }>) {
18
51
return (
19
- < div>
20
- < p> Count: {count}< / p>
21
- < button onClick= {() => setCount (count + 1 )}> Increment< / button>
22
- < / div>
52
+ <html lang = " en" >
53
+ <body className = { inter .className } >
54
+ <ToastProvider >{ children } </ToastProvider >
55
+ </body >
56
+ </html >
23
57
);
24
58
}
25
59
```
60
+
61
+ 5 . Use the [ ` useToast ` ] ( /useToast ) hook in your ** client** components:
62
+
63
+ > 💡 To use the hook, import the ` use client ` directive.
64
+
65
+ ``` tsx
66
+ ' use client' ;
67
+
68
+ import { useToast } from ' @pheralb/toast' ;
69
+
70
+ export default function MyComponent() {
71
+ const toast = useToast ();
72
+ return (
73
+ <button
74
+ onClick = { () =>
75
+ toast .success ({
76
+ text: ' Ready 🚀✨' ,
77
+ })
78
+ }
79
+ >
80
+ Click me!
81
+ </button >
82
+ );
83
+ }
84
+ ```
85
+
86
+ ✨ Ready.
0 commit comments