reactjs - 如何通过组件编辑存储中的数据?反应 JS
问题描述
我已经在我的商店中记录了:false,我需要在 react js 的组件中的按钮操作上将其更改为 true。如果您能告诉我如何编辑/更新商店中的数据或共享链接?
解决方案
如何创建商店
const redux = require('redux');
const createStore = redux.createStore;
const initialState = {
counter: 0
}
const rootReducer = (state = initialState, action) => {
if(action.type === 'INC_COUNTER'){
return {
...state,
counter: state.counter + 1
};
}
return state;
};
如何调用操作
const mapDispatchToProps = dispatch => {
return {
onIncrementCounter: () => dispatch({type:'INC_COUNTER'})
};
};
单击时调用它
<button clicked={this.props.onIncrementCounter} />
推荐阅读
- ionic-framework - Ionic 3 中的键盘上推内容
- mysql - 使用 Inner Join 在 SQL 中查找我们关闭/赢得的机会的百分比是入站还是出站
- command-line - 是否可以使用 linux 命令行组合多个数组?
- python - Django Admin:JSONField 默认空字典不会保存在管理员中
- c# - 比较日期时间 SQL 服务器和 asp.net
- angular - 你如何在 Ngrx 中从一个 Effect 调度多个 Action
- java - Java - 带有轮廓的 Android Mobile Vision 人脸检测
- apache - Apache 启动后无法远程访问我的 EC2
- java - 如何从另一个范围调用变量?
- performance - MarkLogic 内容泵 (MLCP) - 性能 - 记录详细信息