Skip to content

context api

Melissa Stock edited this page Jun 27, 2019 · 1 revision

Context API

  • Use to manage state because it is "global" : Context provides a way to pass data through the component tree without having to pass props down manually at every level

Important Syntax

  • const MyContext = React.createContext(defaultValue);
  • <MyContext.Provider value={/* some value */}>
  • Used inside of classes - static contextType = MyContext;
  • Used inside of app.js - `import {ThemeContext, themes} from './theme-context';
  • Used inside of app.js import ThemedButton from './themed-button';

Clone this wiki locally