javascript - React Redux - 另一个组件中的道具
问题描述
我正在尝试创建一个应用程序,我的应用程序的一部分类似于 Counter 游戏。我有一个完整的组件,但我需要在另一个组件中使用来自该组件的道具的值,以及在另一个组件中增加价值的函数。我该怎么做?
class ClickCounter extends Component { static mapStateToProps = (state) => {
return {
count: state.count
}; }; static mapDispatchToProps = (dispatch) => {
return bindActionCreators(
{
increaseCount,
decreaseCount
},
dispatch
); };
render() {
const { increaseCount, decreaseCount } = this.props;
return (
<div>
<button onClick={increaseCount}>+</button>
<span>{this.props.count}</span>
<button onClick={decreaseCount}>-</button>
</div>
);
}
}
export default connect(
ClickCounter.mapStateToProps,
ClickCounter.mapDispatchToProps
)(ClickCounter);
解决方案
推荐阅读
- reactjs - 用户操作后重新渲染反应组件
- flutter - 将数据从父级传递给子级 StatefulWidget Flutter
- postgresql - 如何使用 SSL/TLS 在 CircleCI 中运行 PostgreSQL?
- java - 用于聚合的 JUnit 测试用例
- android - android:state_pressed 不起作用,按下按钮它不会改变颜色
- html - Quasar QMarkupTable th 粘性标题不起作用
- flutter - 成功登录后在颤动中处理重定向响应
- reactjs - 如何将 useContext 转换为打字稿
- python - 模板不存在于 /
- unity3d - Android资源链接失败:Unity错误:意外元素
在发现