我已经完成了每行代码。检查mapDispatchToProps,检查reducer,改变reducer-switch中每个case的触发顺序,尝试以独奏模式渲染每个组件,以及不带条件渲染。我创建了一个sayHello动作,只有控制台日志说你好。问题是:一些行动正在发挥作用。特别是那些在某个特定事件之前创建的事件(不能在什么时候开始)。
我的简单行动:
export function sayHello(){
return {
type: 'SAY_HELLO'
}
减速器中处理动作的情况:
case 'SAY_HELLO':
console.log('HELLO WORLD')
newState = {...newState}
return newState;
应该触发操作的按钮(我在包含此按钮的组件上执行console.log,它实际上包括sayHello函数以及通过调度映射的所有其他函数):
<button onClick={this.props.sayHello}>sayhello</button>
mapDispatchToProps:
const mapDispatchToProps = (dispatch) => {
return {
changeView: (event) => {
dispatch(changeView(event))
},
updateCarChoice: (event) => {
dispatch(updateCarChoice(event))
},
bookCar: (event) => {
dispatch(bookCar(event))
},
addCar: (event) => {
dispatch: ( addCar(event))
},
removeCar: (event) => {
dispatch: ( removeCar(event))
},
handleSignIn: (event) => {
dispatch: (handleSignIn (event))
},
updateAuthObject: (event) => {
dispatch: (updateAuthObject (event))
},
handleCreateAccount: (event) => {
dispatch: (handleCreateAccount (event))
},
changeAuthType: (event) => {
dispatch: (changeAuthType (event))
},
sayHello: () => {
dispatch: (sayHello ())
}
}
};
商店:
import {createStore, combineReducers, applyMiddleware} from 'redux';
import {createLogger} from 'redux-logger';
import mainReducer from '../reducers/mainReducer';
import carsReducer from '../reducers/carsReducer';
import logInReducer from '../reducers/logInReducer';
export default createStore(
combineReducers({
mainReducer,
carsReducer,
logInReducer
}),
applyMiddleware(createLogger())
);
index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import registerServiceWorker from './registerServiceWorker';
import './index.css';
import {Provider} from 'react-redux';
import store from './store/store';
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root'));
registerServiceWorker();
任何帮助表示赞赏。感谢。
答案 0 :(得分:0)
您没有退回发货:
changeView: (event) => {
dispatch(changeView(event))
},
应该是
changeView: (event) => dispatch(changeView(event))