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