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.createContextwhich returns an object withProviderandConsumercomponentsto the
Providercomponent a prop namedvalueneeds 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
Consumercomponent.
Last updated