An open API service indexing awesome lists of open source software.

https://github.com/dbtek/react-sse

Simple state management with event emitter for React
https://github.com/dbtek/react-sse

event-emitter react state-management

Last synced: 22 days ago
JSON representation

Simple state management with event emitter for React

Awesome Lists containing this project

README

          

## React SSE { }
Simple state management via an event emitter. Inspired from Choo, uses [nanobus](https://github.com/choojs/nanobus).

### Install
```bash
$ yarn add react-sse
# or
$ npm i react-sse --save
```

### Usage
```js
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { withState, addStore } from 'react-sse'

function countStore (state, emitter) {
state.count = 0

emitter.on('count:increase', () => {
state.count++
emitter.emit('render')
})

emitter.on('count:decrease', () => {
state.count--
emitter.emit('render')
})
}

class Counter extends Component {
render () {
const { state, emit } = this.props
return (


{state.count}



emit('count:decrease')}>-
emit('count:increase')}>+



)
}
}

var StatefulCounter = withState(Counter)
addStore(countStore)

ReactDOM.render(, document.querySelector('#app'))
```

### Author
İsmail Demirbilek - [@dbtek](https://twitter.com/dbtek)

### License
MIT