【发布时间】:2018-08-16 18:44:27
【问题描述】:
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 有效。
【问题讨论】:
-
this.onRefresh(this.props.subdomainConfig)返回一个函数,要调用它,您需要在末尾添加一对括号。 -
是的!现在明白了:)
标签: reactjs react-native currying react-lifecycle