Skip to content

Instantly share code, notes, and snippets.

@trygvea
Last active April 24, 2016 12:19
Show Gist options
  • Save trygvea/db7fed0088bc9aff0ebe97cb79b7dd59 to your computer and use it in GitHub Desktop.
Save trygvea/db7fed0088bc9aff0ebe97cb79b7dd59 to your computer and use it in GitHub Desktop.
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
import { Provider, connect } from 'react-redux'
const reducer = (state = {counter:0}, action = {}) => {
switch (action.type) {
case 'INCREMENT':
return {counter: state.counter+1}
default:
return state
}
}
const store = createStore(reducer)
const Counter = props =>
<button onClick={props.onIncrement}>
{props.value}
</button>;
const CounterContainer = connect(
state => ({ value: state.counter }),
dispatch => ({ onIncrement: () => dispatch({type:'INCREMENT'}) })
)(Counter)
ReactDOM.render(
<Provider store={store}>
<CounterContainer />
</Provider>,
document.getElementById('app')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment