heroku / heroku/react-refetch

Pass this.state.data to then(), catch(), andThen() and andCatch() functions for more powerful side effects

Open
#227 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
137
PR merge metrics
No merged PRs in 30d

Description

Does it make any sense to have `this.state.data` available in those handlers? In my case, it's relevant for implementing an infinite scroller, where each fetch **adds** to the previous data and I need to somehow merge it.

Here's how that would look like:

```jsx
const connections = {
widgets: '/api/widget/?limit=20',
loadMore: offset => ({
loadingMore: {
url: `/api/widget/?limit=20&offset=${offset}`,
andThen: (res, meta, data) => ({
widgets: { value: data.widgets.value.concat(res) },
}),
},
}),
};
```

My current workaround is to pass a `getData()` function to `loadMore()` from the component, which works, but isn't nice.

On another note, I would like to have that `data` even in direct mapping functions (`loadMore()`above), so I can do things like optimistic updates.

And, 👍 for this very nice library, thank you for writing it!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.