react-provide
React Components for putting a value in context and fishing it out. Avoids deep chains of prop passing.
Install
npm install react-provide
Usage
api.js
'some' 'items' // Create a Provider that'll put and object called 'api' into contextconst Provider = // Create a helper that pulls 'api' out of context and passes it as a propconst withApi =
list.js
// Use withApi to pass 'api' as a prop to the component <div>api</div>
main.js
// Use the Provider so deeply nested components can use the api in contextReactDOM
API
contextProvider(key)
Create a provider component that can be used to provide a value called key
to nested components in context.
e.g.
const Provider = <Provider foo='bar'> /* your component tree */</Provider>
withContext(key)
Create a function that'll create a component to pull a value called key
from context and pass it as a prop to your component.
e.g.
static propTypes = foo: PropTypesobjectisRequired { return <div>thispropsfoo</div> } 'foo'MyComponent