【发布时间】:2024-04-19 20:55:02
【问题描述】:
作为新的 React 开发人员尝试使用 redux。我想发送一个动作,传递一个字符串,将文本属性更新为新状态。
这是我的做法。
const notesReducer = (state = 'Initial State', action) => {
switch(action.type) {
case "ADD_NOTE":
return({
text: action.text
})
default:
return state;
}
};
const addNoteText = (note) => {
return ({
type: "ADD_NOTE",
text: note
})
};
const store = Redux.createStore(notesReducer);
console.log(store.getState());
store.dispatch(addNoteText('Hello!'));
console.log(store.getState());
动作创建者 addNoteText() 接受一个参数来传递给 text 属性。请帮忙
【问题讨论】:
标签: redux