|
5年前 | |
---|---|---|
.. | ||
es | 5年前 | |
LICENSE | 5年前 | |
README.md | 5年前 | |
forwardRef.d.ts | 5年前 | |
forwardRef.js | 5年前 | |
index.d.ts | 5年前 | |
index.js | 5年前 | |
injectContextAsProp.js | 5年前 | |
mapContextToProps.d.ts | 5年前 | |
mapContextToProps.js | 5年前 | |
package.json | 5年前 | |
transformContext.js | 5年前 |
React context helpers.
npm install @restart/context
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,
);