|
hace 5 años | |
---|---|---|
.. | ||
es | hace 5 años | |
LICENSE | hace 5 años | |
README.md | hace 5 años | |
forwardRef.d.ts | hace 5 años | |
forwardRef.js | hace 5 años | |
index.d.ts | hace 5 años | |
index.js | hace 5 años | |
injectContextAsProp.js | hace 5 años | |
mapContextToProps.d.ts | hace 5 años | |
mapContextToProps.js | hace 5 años | |
package.json | hace 5 años | |
transformContext.js | hace 5 años |
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,
);