Noodles, Poodles and More!

    react-heridux

    0.0.2 • Public • Published

    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)

    Keywords

    none

    Install

    npm i react-heridux

    DownloadsWeekly Downloads

    3

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    92.9 kB

    Total Files

    10

    Last publish

    Collaborators

    • ybochatay