首页 > 解决方案 > 没有在 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。

标签: reactjsreact-nativecurryingreact-lifecycle

解决方案


onRefresh返回一个函数但不调用它。将其更改为

componentDidMount() {
    this.onRefresh(this.props.subdomainConfig)();
}

推荐阅读