@restart/context ![npm](https://camo.githubusercontent.com/27ff4de02668a5bb56d4c5d7428b185dd187a7a0ec0d4c4a7f83c4a4f9bb6548/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f40726573746172742f636f6e746578742e737667)
React context helpers.
Install
npm install @restart/context
Usage
import React from 'react';
import mapContextToProps from '@restart/context/mapContextToProps';
const MyValueContext = React.createContext(null);
function MyComponent(props) {
/* ... */
}
const MyComponentWithMyValue = mapContextToProps(
MyValueContext,
myValue => ({ myValue }),
MyComponent,
);
const withMyValue = Component =>
mapContextToProps(
{
consumers: MyValueContext,
mapToProps: myValue => ({ myValue }),
displayName: `withMyValue(${Component.displayName || Component.name})`,
},
Component,
);