0
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。

4

1 回答 1

4

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

componentDidMount() {
    this.onRefresh(this.props.subdomainConfig)();
}
于 2018-08-16T18:48:18.553 回答