Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
root d8c1b4a1be initial 5 年前
..
es initial 5 年前
LICENSE initial 5 年前
README.md initial 5 年前
forwardRef.d.ts initial 5 年前
forwardRef.js initial 5 年前
index.d.ts initial 5 年前
index.js initial 5 年前
injectContextAsProp.js initial 5 年前
mapContextToProps.d.ts initial 5 年前
mapContextToProps.js initial 5 年前
package.json initial 5 年前
transformContext.js initial 5 年前

README.md

@restart/context npm

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,
  );