JSPM

@restart/context

2.1.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 285822
  • Score
    100M100P100Q163707F
  • License MIT

Package Exports

  • @restart/context
  • @restart/context/forwardRef
  • @restart/context/mapContextToProps

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@restart/context) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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