https://github.com/react-restart/context
React context helpers
https://github.com/react-restart/context
Last synced: 5 months ago
JSON representation
React context helpers
- Host: GitHub
- URL: https://github.com/react-restart/context
- Owner: react-restart
- License: mit
- Created: 2018-05-08T19:44:49.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:38:16.000Z (over 3 years ago)
- Last Synced: 2025-10-22T19:42:07.419Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.43 MB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @restart/context [![npm][npm-badge]][npm]
React context helpers.
## Install
```sh
npm install @restart/context
```
## Usage
```js
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,
);
```
[npm-badge]: https://img.shields.io/npm/v/@restart/context.svg
[npm]: https://www.npmjs.org/package/@restart/context