query
query copied to clipboard
remove `isDataEqual` property on useQuery
We have two props that go together on useQuery that are around structural sharing:
-
isDataEqual?: (oldData: TData | undefined, newData: TData) => boolean- default:
undefined
- default:
-
structuralSharing?: boolean | ((oldData: TData | undefined, newData: TData) => TData)- default:
true
- default:
This is how it works internally when new data comes in, and we need to consolidate it with existing data:
- At first, we check if
isDataEqualis passed. If it is, and it returns true, we just return the previousData. - If it's not we used to check if
structuralSharingis on (boolean). If it's not, we returned the new data - If
structuralSharingis on, we try to re-use as much as possible frompreviousDatato keep referential identity. This sharing is not for free, so you can turn it off. It also only works on json compatible values per default.
With v4.2.0, we added a feature for custom structuralSharing functions. This way, consumers can still achieve the performance benefits of retained references even when cache data contains non-serializable values.
This feature has a nice side effect: you can now implement isDataEqual with it. All you need to do instead is do the same check in your structuralSharing function and return oldData if they are equal instead of true. The functions also have the exact same interface for the parameters passed in:
structuralSharing: (oldData, newData) =>
isDataEqual(oldData, newData) ? oldData : replaceEqualDeep(oldData, newData)
proposal
- ✅ Deprecate
isDataEqualin v4- show that you can implement it with
structuralSharing. For this to work, we also need to expose the internal functionality that structural sharing is doing (currently namedreplaceEqualDeep).
- show that you can implement it with
- Remove
isDataEqualfromuseQueryin v5