Skip to main content
100%

Context

✓ Published1🌍 Public
MMark Lam
Last edited Apr 24, 2022
Created on Apr 24, 2022
Forked from React Starter

This example demonstrates the React Context API for sharing a user name across components. It shows a large, centered text message ("Joe") rendered by a `UserProfile` component, which consumes the context value. The code defines a `UserContext` with `Provider` and `Consumer` exports, and uses `UserProvider` to supply the value. The rendering relies on React's `createContext` and `useContext` hooks, with the `UserConsumer` passing the context to a paragraph element. The tight coupling between `App.js` and `User.js` overrides the provider value, resulting in the displayed name.

AI-generated description

React Starter code.

MIT Licensed

Similar vizzes