@asphalt-react/context
Version:
share context among asphalt components
36 lines (24 loc) • 941 B
Markdown
# @asphalt-react/context

> ⚠️ Designed for Asphalt React component packages. Use at your own risk, if using externally.
A package which contains a React `context` which is to be shared among **asphalt** components.
## Why
There are use cases, where two different packages need to communicate. In such cases, rather than creating inter-package dependency, they both can import `@asphalt-react/context` and use `Provider` and `Consumer` from it.
## Usage
### Provider
```js
import Component2 from "@asphalt-react/component"
import { Provider } from "@asphalt-react/context"
export default (Component = () => (
<Provider value={{ id: 1 }}>
<Component2 />
</Provider>
))
```
### Consumer
```js
import { Provider } from "@asphalt-react/context"
export default (Component2 = () => (
<Consumer>{({ id }) => <span>{id}</span>}</Consumer>
))
```