InfiniteLoader and reaction reduction

The InfiniteLoader component from react-virtualized requires that the function be passed as the loadMoreRows property in order to have a type signature { startIndex: number, stopIndex: number }): Promise. I use shorthand in my project, so I am the loadMoreRowscreator of the action as a shorthand:

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)
      )
    }
  }
}

after that, this action is associated with the reactive component containing the InfiniteLoader using the join function from the reduct reduction.

So I'm not sure how I can satisfy the signature requirements, as the creators of action-action do not return any value /

+4
source share
1 answer

eyeinthebrick . .

"" Redux, () Promise. , , , - ...

function fetchEntities (start, stop) {
  return fetch(`${myUrl}&start=${start}?stop=${stop}`)
}

const loadMoreRows = ({ startIndex, stopIndex }) => {
  return async (dispatch, getState) => {
    try {
      const items = await fetchEntities(startIndex, stopIndex)
      await dispatch(simpleAction(items))
    } catch (error) {
      console.log(error)
    }
  }
}

InfiniteLoader Redux.

+2

Source: https://habr.com/ru/post/1650142/


All Articles