@@ -20,6 +20,37 @@ npm i @nimpl/context
2020yarn add @nimpl/context
2121```
2222
23+ ## Usage
24+
25+ ``` tsx
26+ // stores/app-store/contexts.server.tsx
27+ import createServerContext from " @nimpl/context/create-server-context" ;
28+ export const AppServerContext = createServerContext <{ data: string | null }>({
29+ data: null ,
30+ });
31+
32+ // components/parent-component
33+ import { AppServerContext } from " @/stores/app-store/contexts.server" ;
34+ import { ChildComponent } from " ./child-component" ;
35+
36+ export const ParentComponent = () => (
37+ {/* Same as <AppServerContext.Provider /> */ }
38+ <AppServerContext value = { { data: " test" }} >
39+ <ChildComponent />
40+ </AppServerContext >
41+ );
42+
43+ // components/child-component
44+ import getServerContext from " @nimpl/context/get-server-context" ;
45+ import { AppServerContext } from " @/stores/app-store/contexts.server" ;
46+
47+ export const ChildComponent = () => {
48+ const context = getServerContext (AppServerContext );
49+
50+ return <div >{ context .data } </div >;
51+ };
52+ ```
53+
2354## Stability
2455
2556All context are covered with tests. Tests are run on every release and every 6 hours on the latest ** Canary** version of ` Next.js ` .
@@ -28,7 +59,7 @@ In this way, you can be sure not only of the stability of the code, but also tha
2859
2960## Examples
3061
31- You can see examples in the [ directory] ( https://github.com/vordgi /nimpl-context/tree/main/examples ) of the repository.
62+ You can see examples in the [ directory] ( https://github.com/alexdln /nimpl-context/tree/main/examples ) of the repository.
3263
3364## Additional
3465
@@ -38,4 +69,4 @@ Create issues for identified issues, desired getters, or various improvements.
3869
3970## License
4071
41- [ MIT] ( https://github.com/vordgi /nimpl-context/blob/main/LICENSE )
72+ [ MIT] ( https://github.com/alexdln /nimpl-context/blob/main/LICENSE )
0 commit comments