如何将多个函数调用与重组结合在一起?

时间:2018-09-03 06:30:36

标签: reactjs recompose

我的类组件中有一个函数,我想使用recompose进行重构:

handleSelected = lang => {
    this.setState({
        selected: lang
    })
    fetchPopularRepos(lang).then(repos => {
        this.setState({
            selected: lang,
            repos
        })
    })
}

const handleSelected = props => lang => {
        this.setState({
            selected: lang,
            repos: null
        })
        fetchPopularRepos(lang).then(repos => this.setState({ repos }))
    }

const withPopularReposState = withStateHandlers(initialState, {
    handleSelected
})

这当然不起作用,并且出现错误Cannot read property 'setState' of undefined。如何将多个函数调用与重组结合在一起?

0 个答案:

没有答案