query icon indicating copy to clipboard operation
query copied to clipboard

feat: determine whehter suspend by user

Open liaoliao666 opened this issue 2 years ago • 3 comments

liaoliao666 avatar Jul 28 '22 15:07 liaoliao666

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit dc424d868ab1db0fc093e985cd1316be336da7c9:

Sandbox Source
@tanstack/query-example-react-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration

codesandbox-ci[bot] avatar Jul 28 '22 15:07 codesandbox-ci[bot]

Unfortunately with () => true as suspense it goes into infinite fetch loop Reproduction link -> https://codesandbox.io/s/heuristic-neumann-ohjy5e

kamilkazmierczakMtab avatar Aug 09 '22 09:08 kamilkazmierczakMtab

@kamilkazmierczakMtab I think it is no problem. cuz it is different between () => true with true for suspense. if set suspense as function that it means that this function should have a boundary conditions to return true

liaoliao666 avatar Aug 09 '22 15:08 liaoliao666

I see, I thought along with @TkDodo that it can allow to force Suspense to be triggered on non-initial fetches e.g. by calling invalidateQueries like in attempt to do it in my previous example in codesandbox

kamilkazmierczakMtab avatar Aug 10 '22 10:08 kamilkazmierczakMtab

@kamilkazmierczakMtab But this is what i wanted. I wanna force Suspense whenever i want. I'm still do not understand what u worry about, cuz it's completely control by developer.

liaoliao666 avatar Aug 10 '22 15:08 liaoliao666

I wanna force Suspense whenever i want.

I think you can get the same behaviour with queryClient.resetQueries actually. reset will clear the data from the cache, and then re-render your component. At that point, it will see that there is no data, go fetch it and suspend. I think this would be the better solution to the problem you're trying to solve, wouldn't it ?

TkDodo avatar Aug 12 '22 07:08 TkDodo

given that we have resetQueries that can likely do exactly what we want, I don't think I'm going to merge this. Also, there is some talk on twitter about a new suspense api coming, and it might be a hook, so calling suspense conditionally might make it more difficult to adapt.

TkDodo avatar Aug 12 '22 13:08 TkDodo

okay😂

liaoliao666 avatar Aug 12 '22 15:08 liaoliao666