Skip to content

Instantly share code, notes, and snippets.

@namelos
Last active February 19, 2016 10:58
Show Gist options
  • Save namelos/94b522c4c9394f9b4b1d to your computer and use it in GitHub Desktop.
Save namelos/94b522c4c9394f9b4b1d to your computer and use it in GitHub Desktop.
Minimalist redux example
import React, { Component } from 'react'
import { render } from 'react-dom'
import { createStore, bindActionCreators } from 'redux'
import { connect, Provider } from 'react-redux'
const increment = () => ({ type: 'increment' })
const counter = (state = 0, action) => {
switch (action.type) {
case 'increment':
return state + 1
default:
return state
}
}
const store = createStore(counter)
const mapState = counter => ({ counter })
const mapDispatch = dispatch => bindActionCreators({ increment }, dispatch)
@connect(mapState, mapDispatch)
class Counter extends Component {
render = () => <h1 onClick={ this.props.increment }>
{ this.props.counter }
</h1>
}
render(
<Provider store={ store }>
<Counter />
</Provider>,
document.getElementById('root'))
@uinz
Copy link

uinz commented Aug 31, 2015

能写个中间件 / 异步方面的小样吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment