export default connect(
mapStateToProps,
mapDispatchToProps
)(Home)
import { connect } from 'react-redux'
export default connect(
mapStateToProps,
mapDispatchToProps
)(Home)
function mapStateToProps(state) {
return {
number: state.count.number
}
}
import { combineReducers } from 'redux'
const initialState={
number:2
};
function update(state = initialState, action) {
switch (action.type) {
case 'INCREASE':
console.log("INCREASE");
console.log(state);
return {
number: state.number+action.payload
};
case 'DECREASE':
console.log("DECREASE");
console.log(state);
return {
number:state.number-action.payload
};
default:
return state;
}
}
export default combineReducers({
count: update,
})
const mapStateToProps = (state, ownProps) => {
return {
active: ownProps.filter === state.visibilityFilter
}
}
function mapDispatchToProps(dispatch) {
return {
setIncrease: (state) => dispatch(state),
setDecrease: (state) => dispatch(state)
}
}
import React, { Component } from 'react';
import { createStore} from 'redux'
import { Provider } from 'react-redux'
import {BrowserRouter } from 'react-router-dom';
import { Route } from 'react-router'
import reducers from '../reducer/index.js'
import App from '../views/App.js'
import Home from '../views/Home.js'
import Another from '../views/Another.js'
const store = createStore(reducers);
export default class RouterIndex extends Component {
render() {
return (
)
}
}
源码见:https://github.com/DuFanFan1/react-redux-demo