Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
root d8c1b4a1be initial il y a 5 ans
..
es initial il y a 5 ans
LICENSE initial il y a 5 ans
README.md initial il y a 5 ans
forwardRef.d.ts initial il y a 5 ans
forwardRef.js initial il y a 5 ans
index.d.ts initial il y a 5 ans
index.js initial il y a 5 ans
injectContextAsProp.js initial il y a 5 ans
mapContextToProps.d.ts initial il y a 5 ans
mapContextToProps.js initial il y a 5 ans
package.json initial il y a 5 ans
transformContext.js initial il y a 5 ans

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