Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
root d8c1b4a1be initial 5 vuotta sitten
..
es initial 5 vuotta sitten
LICENSE initial 5 vuotta sitten
README.md initial 5 vuotta sitten
forwardRef.d.ts initial 5 vuotta sitten
forwardRef.js initial 5 vuotta sitten
index.d.ts initial 5 vuotta sitten
index.js initial 5 vuotta sitten
injectContextAsProp.js initial 5 vuotta sitten
mapContextToProps.d.ts initial 5 vuotta sitten
mapContextToProps.js initial 5 vuotta sitten
package.json initial 5 vuotta sitten
transformContext.js initial 5 vuotta sitten

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