Skip to content

useQuery always return a new "data" instance #430

Closed
@tiagoengel

Description

@tiagoengel

The data object returned by useQuery is always different after a server request is executed, even when the server response is exactly the same.

This can be problematic in some cases, for example using data on a useEffect hook will cause the hook to be executed every time a request is sent, when what I would expect is for it to be triggered only when the actual data changes.

It's also worth noting this is not the case with swr, it will only trigger other hooks when the actual data has changed.

If this is a conscious design decision, it would be great to have it documented. For my current project this is a deal breaker, and it would have saved me some time to know this before hand.

I've created a simple example here https://codesandbox.io/s/react-query-memo-wlw2v?file=/src/App.tsx. You can switch between swr and react-query on line 18 and check in the console to see how memo is triggered every time a request is done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions