gpt4 book ai didi

javascript - curry 函数导致错误但如果不 curry 则有效

转载 作者:行者123 更新时间:2023-11-30 10:59:35 25 4
gpt4 key购买 nike

export const postMoviePopular = url = dispatch => {
const data = axios.get(url);
dispatch(saveMoviePopular(data));
}

const saveMoviePopular = payload => {
return {
type: POST_MOVIE_POPULAR,
payload
}
}

这是我的代码,它不起作用,因为它是柯里化(Currying)的,但如果它不是像下面这样柯里化(Currying)的,它就可以工作,这是为什么??

export const postMoviePopular = url => {
return dispatch => {
const data = axios.get(url);
dispatch(saveMoviePopular(data));
}
}

我想知道这是否与我调用 mapDispatchToProps 的方式有关???

componentDidMount() {
this.props.postMDBConfig(`https://api.themoviedb.org/3/configuration?api_key=${this.props.apiKey}`);
this.props.postMoviePopular(`https://api.themoviedb.org/3/movie/popular?api_key=${this.props.apiKey}&language=en-US&page=1&region=US`)
}

const mapDispatchToProps = (dispatch) => {
return {
postMDBConfig: url => dispatch(postMDBConfig(url)),
postMoviePopular: url => dispatch(postMoviePopular(url))
}
}

最佳答案

您需要一个返回语句。还有一个箭头。

export const postMoviePopular = url => dispatch => {
const data = axios.get(url);
return dispatch(saveMoviePopular(data));
}

关于javascript - curry 函数导致错误但如果不 curry 则有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58450209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com