GoScrobble/web/node_modules/@restart/context
2022-04-25 14:48:54 +12:00
..
es 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
forwardRef.d.ts 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
forwardRef.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
index.d.ts 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
index.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
injectContextAsProp.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
LICENSE 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
mapContextToProps.d.ts 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
mapContextToProps.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
package.json 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
README.md 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
transformContext.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00

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