Skip to content

Instantly share code, notes, and snippets.

@pietgeursen
Created July 11, 2016 02:48
Show Gist options
  • Save pietgeursen/c52ea498aa38dc794b1dac204ba4a2e5 to your computer and use it in GitHub Desktop.
Save pietgeursen/c52ea498aa38dc794b1dac204ba4a2e5 to your computer and use it in GitHub Desktop.
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