The Context API (React 16.3)
The context API is usually used for global data. This can help with the overly complicated props-chain.
In /context/auth-context.js
1 | import React from 'react'; |
To use context in application: wrap the components that need context data into the context component.
1 | // App.js |
contextType
and useContext
1 | import AuthContext from './context/auth-context'; |
useContext()
in React Hooks.
1 | import { useContext } from 'react'; |