Stores
import { createStore } from 'redux';
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT': return state + 1;
case 'DECREMENT':return state - 1;
default: return state;
}
}
let store = createStore(counter);
store.subscribe(() => { ... })
store.dispatch({ action })
store.getState()
store.dispatch({ type: 'INCREMENT' }); // 1
store.dispatch({ type: 'DECREMENT' }); // 10
React Redux
React.render(<Provider store={store}>{() => <App />}</Provider>, mountNode)
class App extends React.Component {
render () { return <div>{this.props.message}</div> }
}
function select (state) {
return { message: state.message }
}
export default connect(select)(App);
Комментариев нет:
Отправить комментарий