Created
July 11, 2016 02:48
-
-
Save pietgeursen/c52ea498aa38dc794b1dac204ba4a2e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 as renderDom } from 'react-dom' | |
import {createStore} from 'redux' | |
const INCREMENT = 'INCREMENT' | |
const increment = (howMuch) => { return {type: INCREMENT, amount: howMuch} } | |
const Counter = (props) => { | |
return ( | |
<div> | |
<h2>Hi, I got the count: {props.count} </h2> | |
<button onClick={()=> props.dispatch(increment(4))}>up</button> | |
</div> | |
) | |
} | |
const countReducer = (state = 0, action) => { | |
switch (action.type){ | |
case INCREMENT: | |
return state + action.amount | |
case 'DECREMENT': | |
return state - 1 | |
default: return state | |
} | |
} | |
const store = createStore(countReducer) | |
const redraw = () => { | |
renderDom( | |
<Counter count={store.getState()} dispatch={store.dispatch} />, | |
document.querySelector('main')) | |
} | |
store.subscribe(redraw) | |
redraw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment