amplitude / redux-query

A library for managing network state in Redux
https://amplitude.github.io/redux-query
Other
1.1k stars 67 forks source link

Introduce useRequestOnDemand hook #269

Closed kelsonpw closed 2 years ago

kelsonpw commented 2 years ago

This PR introduces a hook that supports:

Previously, there was no way to send a GET request on demand via React Hook (outside of component render lifecycle).

The implementation is based off of useMutation. The main difference is that we are just dispatching requestAsync under the hood.

kelsonpw commented 2 years ago

lgtm following the useMutation patterns.

Did this become a much more common want? We have been able to work around it in the past by just manually dispatching requestAsync actions. It's a bit more clunky than a proper hook but it just didn't come up that much.

After introducing a Rest API, we've had a frequent want for a hook that allows us to make GET requests on demand, not on mount, and easy, ergonomic access to the request's query state. dispatch(requestAsync(qc)) definitely works for the majority, but not all.