Created
March 30, 2017 17:54
-
-
Save a-eid/8b34df0139fded4cd5eb30bc98746d40 to your computer and use it in GitHub Desktop.
simple counter example ....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {render} from 'react-dom'; | |
import {createStore} from 'redux' | |
const reducer = (state = 0 , action) => | |
(action.type == 'inc' || action.type == 'dec') ? ((action.type == 'inc' ? state + 1 : state - 1) ) : state | |
const store = createStore(reducer) | |
const Counter = ({value , onInc , onDec}) => ( | |
<div> | |
<h1>{value}</h1> | |
<button onClick={onInc}>+</button> | |
<button onClick={onDec}>-</button> | |
</div> | |
) | |
const init = ()=> { | |
render(<Counter value={store.getState()} onInc={()=> store.dispatch({type: 'inc'})} onDec={()=> store.dispatch({type: 'dec'})}/> , document.getElementById('root')) | |
} | |
init() | |
store.subscribe(init) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment