react-request icon indicating copy to clipboard operation
react-request copied to clipboard

Question: update all instances of a request when one instance is updated through `doFetch`?

Open angusfretwell opened this issue 7 years ago • 1 comments

Hi!

Our app has two instances of the same Fetch component which are both rendered at the same time. When calling doFetch on one (which causes the cache to be updated) the other component is not updated. Is there a way to achieve this?

angusfretwell avatar Jul 27 '18 04:07 angusfretwell

There is not currently a way to achieve this by solely using React Request. This is by design, but I'd be open to consider what a subscription/observable/stream-like API would look like.

tl;dr, React Request is supposed to help with fetching data from a server, but it isn't supposed to be a full-on replacement for a data store (such as Redux, Mobx, or Apollo in-memory cache). Because of this design decision, you don't see features like this in React Request:

  • normalization
  • models/entities/resources
  • schemas
  • direct cache reads/writes
  • subscriptions

The intention is that you would use React Request along with a data store that provides additional functionality that you need. For most React users today, that is likely Redux.

If you are interested in developing a subscription/observable/streams API, then you would probably want to start over in fetch-dedupe. That is the library that React Request is built off of, and right now it stores Promises in its cache. Promises can only resolve a single time, so it is not possible to subscribe to further updates to the value. If you have the time and want to brainstorm an API, I would absolutely consider it!

Thanks for the issue!

jamesplease avatar Jul 27 '18 06:07 jamesplease