mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
.. | ||
es | ||
forwardRef.d.ts | ||
forwardRef.js | ||
index.d.ts | ||
index.js | ||
injectContextAsProp.js | ||
LICENSE | ||
mapContextToProps.d.ts | ||
mapContextToProps.js | ||
package.json | ||
README.md | ||
transformContext.js |
@restart/context
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,
);