heroku / heroku/react-refetch

Composing requests within the connect function (enhancement)

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

Description

I can see in the docs the ability to use `PromiseState.all` in the component to put together a number of existing Promise states on the props. This is cool, however I was thinking it would be particularly neat if it could be abstracted out to the `connect` function such that a composed `PromiseState` could be directly passed down into the props from there.

For example:
```js
connect(props => ({
usersFetch: props.users.map(user => `/users/${user.id}`)
}))(App)
```
Which is then interacted with in the component `App` like so:
```js
render() {
return this.props.usersFetch.fulfilled &&
this.props.usersFetch.value.map(user => ())
}
```

Here it defaults the composed `PromiseState` to the completion of `all` of the contained PromiseState as opposed to the `race` option (can't think off the top of my head of a way to allow this to be nicely configurable though, since passing the array is the neatest and most simplistic means at the moment)

Would love to contribute to this project, so if this is a good idea and we can agree on implementation I'd happily code up a PR 👍

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.