Skip to content

react-restart/context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

07b82dd · Jan 1, 2023

History

51 Commits
Mar 29, 2019
Feb 26, 2019
Jan 1, 2023
Mar 29, 2019
Mar 29, 2019
Feb 26, 2019
May 9, 2018
Feb 26, 2019
Mar 29, 2019
Jul 27, 2018
Mar 29, 2019
Jul 21, 2020
Sep 11, 2020

Repository files navigation

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