reactjs - 没有在 componentDidMount 中调用 Curried 函数
问题描述
componentDidMount() {
this.onRefresh(this.props.subdomainConfig)
}
onRefresh = config => () => {
console.log('onRefresh', config)
}
在这个反应组件中,当组件安装时,onRefresh 函数根本不会被调用。如果我将此函数用于 RefreshControl,那么它将被调用。
<ScrollView
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this.onRefresh(this.props.subdomainConfig)}
/>
}>
<ZoneListComponent
zones={zones}
onPressEdit={this.onPressEdit}
/>
</ScrollView>
感谢有人能告诉我为什么这没有在 componentDidMount 中被调用,而是适用于 RefreshControl。
解决方案
onRefresh
返回一个函数但不调用它。将其更改为
componentDidMount() {
this.onRefresh(this.props.subdomainConfig)();
}
推荐阅读
- css - cdk拖放图像不起作用
- amazon-web-services - 在 AWS prod 阶段删除 API Gateway 资源
- reactjs - 反应标签不显示图像
- java - 按数组选择行包含检查
- unit-testing - Azure DevOps Pipeline:在本地通过的测试在管道上失败
- c# - Asp.Net MVC:How to get selected option from DropDownListFor in Action on submit
- ios - 如何使用 Firestore 快速引用当前登录的用户?
- python - 以固定间隔循环列和平均元素
- python - 将数据类型更改为 float 或 numpy float
- javascript - 尝试替换时缺少部分字符串