react-heridux
v0.0.2
Published
use heridux with react
Downloads
3
Readme
react-heridux
Use heridux with react
Installation
With npm or yarn.
npm install react-heridux
yarn install react-heridux
Basic example
import React from "react"
import ReactDOM from "react-dom"
import Heridux from "react-heridux"
Heridux.createReduxStore()
/////////////////////////////////////////////////////
const hStore = new Heridux("counterStore")
hStore.setInitialState({ counter : 0 })
hStore.createAction("increment", state => (
state.set("counter", state.get("counter") + 1)
))
hStore.createAction("decrement", state => (
state.set("counter", state.get("counter") - 1)
))
hStore.register()
/////////////////////////////////////////////////////
class MyComponent extends React.Component {
increment() { hStore.execAction("increment") }
decrement() { hStore.execAction("decrement") }
render() {
return (
<div>
<p>
Clicked: <span id="value">{ this.props.counter }</span> times
<button onClick={ this.increment }>+</button>
<button onClick={ this.decrement }>-</button>
</p>
</div>
)
}
}
const mapStateToProps = state => ({
counter : state.get("counter")
})
export default hStore.connect(mapStateToProps)(MyComponent)