【发布时间】:2016-12-10 07:34:29
【问题描述】:
来自react-virtualised 的组件 InfiniteLoader 要求作为属性 loadMoreRows 传递的函数具有类似{ startIndex: number, stopIndex: number }): Promise 的签名。
我在我的项目中使用 redux,所以 loadMoreRows 是这样的 redux 动作创建者:
const fetchEntities(start, stop) {
return fetch(`${myUrl}&start=${start}?stop=${stop}`)
}
const loadMoreRows = ({ startIndex, stopIndex }) => {
return (dispatch, getState) => {
return function(dispatch) {
return fetchEntities(startIndex, stopIndex).then(
items => dispatch(simpleAction(items)),
error => console.log(error)
)
}
}
}
之后,使用 react-redux 的 connect 函数将这个 action 连接到包含 InfiniteLoader 的 react 组件。
所以我不确定,我怎样才能满足签名要求,因为 redux 动作创建者不返回任何值/
【问题讨论】:
-
我从 react-virtualised 的源代码中了解到,不需要从 loadMoreRows 函数返回 Promise。但是,如果您不这样做,您有义务调用 child.forceUpdate() 来更新底层组件。
标签: react-redux react-virtualized