https://github.com/thekashey/react-push-channel
🎈Context is to drill props down. React Push Channel to drill props up.
https://github.com/thekashey/react-push-channel
context events props react react-helmet react-side-effect
Last synced: 11 months ago
JSON representation
🎈Context is to drill props down. React Push Channel to drill props up.
- Host: GitHub
- URL: https://github.com/thekashey/react-push-channel
- Owner: theKashey
- Created: 2018-08-15T12:51:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-08T12:10:25.000Z (about 6 years ago)
- Last Synced: 2025-06-24T23:05:50.110Z (11 months ago)
- Topics: context, events, props, react, react-helmet, react-side-effect
- Language: TypeScript
- Homepage:
- Size: 1.35 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-push-channel
[](https://greenkeeper.io/)
----
[](https://nodei.co/npm/react-push-channel/)
Context is to drill props down. React Push Channel drill props up.
# API
#### `createChannel(initialValue, reducer?, initialValueForReducer?)`
creates a channel, with given initialValue(used for typing), and optional reducer.
Reducer will be applied to all stored `messages`, producing the result.
createChannel return an object with 3 fields:
- `Collector` - to collect all messages.
- `callback` - current value will be reported via callback.
- `[merge]` - enabled reducer on data. Ie merges everything into a single value. Otherwise would return last value.
- `Push` - put message into the channel
- any props from initialValue
- `Pop` - read the current active message. Pop __doesn't remove the message__(ie "pops"). Only `Push` component unmount removes it.
## Use as React-helmet?
```js
import {createChannel} from 'react-push-channel';
const helmet = createChannel({
title: '',
description: ''
});
// the root collector
this.setState({helmet})} // transfer reported info into the state
merge // merge all data in reverse order
>
// or actually do the job
document.title=helmet.title} // actually SET THE TITLE!
merge
>
acc + 1, 0);
this.setState({locked: !!locked})}>
{locked => is {locked?'locked':'unlocked'}
// ^^ would be 1 and `locked`
```
# Licence
MIT