React Context
React Context (in React 16+ versions) allows you to pass some data down the component tree without having to pass it via props
from parent to child to further down the component tree.
Create the context in a component from where you want data to be passed on down the component tree using
React.createContext
which returns an object withProvider
andConsumer
componentsto the
Provider
component a prop namedvalue
needs to be provided that can have any value, it could be a string or a number or can be some complex objectIn the children component, this value can be accessed a parameter to a function wrapped inside the
Consumer
component.
Last updated