react-context-store
ReactSmartContext is a lightweight library that helps you use React Context efficiently and with less boilerplate code. Pass in an object of the initialState
and any methods you want and you'll receive an object of a Provider
component, Consumer
component, and withConsumer
HOC. See below for details.
For more information on why this is important, see this article by Ryan Florence.
Before
const ColorContext = React;Component state = color: 'orange' { this; } { return <ColorContext.Provider =>thispropschildren</ColorContext.Provider> ; } const withConsumer = WrappedComponent providerName = 'provider' props <Consumer> store <WrappedComponent /> </Consumer>; ;
After
const Provider Consumer withConsumer = ;;