Dashboard sipadu mbip
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
root d8c1b4a1be initial 5 år sedan
..
es initial 5 år sedan
LICENSE initial 5 år sedan
README.md initial 5 år sedan
forwardRef.d.ts initial 5 år sedan
forwardRef.js initial 5 år sedan
index.d.ts initial 5 år sedan
index.js initial 5 år sedan
injectContextAsProp.js initial 5 år sedan
mapContextToProps.d.ts initial 5 år sedan
mapContextToProps.js initial 5 år sedan
package.json initial 5 år sedan
transformContext.js initial 5 år sedan

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