在尝试创建简单的redux流时,在尝试调度事件时,我在mapDispatchToProps中收到一条错误消息,指出我声明的函数:“警告:未知的事件处理程序属性onProjectCreate
。它将被忽略。 “
我正在将材料UI与最新的节点/ redux库一起使用。
index.js文件:
import reducer from "./store/reducer";
const store = createStore(reducer, applyMiddleware(thunk));
const app = (
<Provider store={store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>
);
reducer.js文件
import * as actionTypes from "./actions";
const initialState = {
projects: [
{
projectName: "test",
description: "new description",
members: "joni@gmail.com",
projectType: "kanban"
}
]
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.CREATE_PROJECT:
console.log(action.title);
return {
...state,
projects: {
...state.projects
}
};
default:
return state;
}
};
export default reducer;
actions.js文件
export const CREATE_PROJECT = 'CREATE_PROJECT';
我在其中使用的组件
import { connect } from "react-redux";
import * as actionTypes from "../../../../store/actions";
/ simplified component
return (
<Grid item xs={12}>
<Button
onClick={onProjectCreate}
variant="contained"
color="primary"
className={classNames(classes.button, classes.paddingExtra)}
>
Create
</Button>
</Grid>
)
const mapStateToProps = state => {
return {
projects: state.projects
};
};
const mapDispatchToProps = dispatch => {
return {
onProjectCreate: () => dispatch({ type: actionTypes.CREATE_PROJECT })
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles)(NewProjectDialog));
您是否知道可能会发生什么? 我已经花了几个小时试图解决这个问题。 谢谢。