I'd like to be able to eliminate the need for the shouldPoll status, which I'm currently updating after unwrapping createOrder and comparing/updating in render.
If pollingInterval accepted a callback that received the current query data (and possibly other flags like isSuccess) I could use the current state of the data to determine if the query should keep polling:
May not be clear how to restart polling after data has reached a certain state. You essentially need to call refetch, and hope the data has changed, or change the query args
If including flags like isSuccess, isFetching etc., it may not be clear if pollingInterval is only evaluated when data changes, or when the flags themselves change.
I think this could be done without a breaking change given the option currently only accepts a number.
Use case:
FAILED
. Currently my component looks a bit like thisHere's a rough WIP of how I would see this looking in practice:
I'd like to be able to eliminate the need for the
shouldPoll
status, which I'm currently updating after unwrappingcreateOrder
and comparing/updating in render.If
pollingInterval
accepted a callback that received the current query data (and possibly other flags likeisSuccess
) I could use the current state of the data to determine if the query should keep polling:With this in place, if a payment fails:
createOrder
mutationI then no longer need local state or to unwrap my mutation result in
handleSubmit
.Tanstack Query has a similar API via
refetchInterval
- https://tanstack.com/query/latest/docs/framework/react/reference/useQueryThe possible drawbacks I can see are:
refetch
, and hope the data has changed, or change the query argsisSuccess
,isFetching
etc., it may not be clear ifpollingInterval
is only evaluated whendata
changes, or when the flags themselves change.I think this could be done without a breaking change given the option currently only accepts a number.