silverwolf-x/project / examples /with-context-api
32.9 GB
31,201 files
Updated 2 months ago
Name
Size
app
_components
tsconfig.json599 Bytes
xet
package.json334 Bytes
xet
README.md1.67 kB
xet
.gitignore454 Bytes
xet
README.md

Hello World example

This example shows how to use react context api in our app.

It provides an example of using app/layout.tsx to include the context api provider and then shows how both the app/page.tsx and app/about/page.tsx can both share the same data using the context api consumer.

We start off by creating two contexts. One that actually never changes (CounterDispatchContext) and one that changes more often (CounterStateContext).

The app/page.tsx shows how to, from the home page, increment and decrement the context data by 1 (a hard code value in the context provider itself).

The app/about/page.tsx shows how to pass an increment value from the about page into the context provider itself.

Deploy your own

Deploy with Vercel

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

npx create-next-app --example with-context-api with-context-api-app
yarn create next-app --example with-context-api with-context-api-app
pnpm create next-app --example with-context-api with-context-api-app

Deploy it to the cloud with Vercel (Documentation).

Total size
32.9 GB
Files
31,201
Last updated
Sep 26
Pre-warmed CDN
US EU US EU

Contributors