未在componentDidMount中调用咖喱函数

时间:2018-08-16 18:44:27

标签: reactjs react-native currying react-lifecycle

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

onRefresh = config => () => {
    console.log('onRefresh', config)
}

在此React组件中,安装组件时根本不会调用onRefresh函数。如果我将此函数用于RefreshControl,则会被调用。

<ScrollView
    refreshControl={
        <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this.onRefresh(this.props.subdomainConfig)}
        />
    }>
    <ZoneListComponent
        zones={zones}
        onPressEdit={this.onPressEdit}
    />
</ScrollView>

欣赏是否有人可以告诉我为什么未在componentDidMount中调用而是为RefreshControl工作的原因。

1 个答案:

答案 0 :(得分:4)

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

componentDidMount() {
    this.onRefresh(this.props.subdomainConfig)();
}
相关问题