我读有反应,终极版和书面咚的JavaScript在下面的例子:返回什么?
在actions.js创建行动:
function fetchPosts(subreddit){
return dispatch => {
dispatch(requestPosts(subreddit))
return fetch(`...URL...`)
.then(response => response.json())
.then(json => dispatch(receivePosts(subreddit, json)))
}
}
export function fetchPostsIfNeeded(subreddit) {
return (dispatch, getState) => {
if (shouldFetchPosts(getState(), subreddit)) {
return dispatch(fetchPosts(subreddit))
}
}
什么是 “fetchPosts(版(Subreddit))” 回归?。
我不明白什么“return dispatch =>”是。
此功能导入并在容器中使用派遣行为,所以我觉得 “调度”是“反应-redux'in容器如下进口函数:
import {fetchPostsIfNeeded} from "../actions"
import {connect} from "react-redux"
...
componentDidMount() {
const { dispatch, selectedSubreddit } = this.props
dispatch(fetchPostsIfNeeded(selectedSubreddit))
}
...
不“调度“在箭头之前表示一个函数,”dispatch(requestPosts(subreddit))“?
是否发出“ES(调度)”与ES2015缩写的参数?
谢谢!我明白这个“dispatch”是一个函数,并返回一个箭头函数。 当这个函数中的所有“dispatch”都改成其他名字时,这个函数仍然像你说的那样工作。 非常感谢! – user2255716