examples/with-context-api/README.md
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.
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).