-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: remove keepPreviousData
in favor of placeholderData
#4715
Conversation
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 d6058fe:
|
Tanner's poll wasn't very conclusive. I would keep the default
I would say exposing a function called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice work 🚀
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## v5 #4715 +/- ##
=====================================
Coverage ? 90.88%
=====================================
Files ? 85
Lines ? 3455
Branches ? 889
=====================================
Hits ? 3140
Misses ? 294
Partials ? 21 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
686e9b1
to
e26789f
Compare
0d22f9a
to
1846404
Compare
@TkDodo @artysidorenko So when i tried to come up with identity function, it somehow messes up with the types returned from // This works - const state: UseQueryResult<number, unknown>
const query1 = useQuery({
queryKey: [key, count],
queryFn: async () => {
return Promise.resolve(count)
},
placeholderData: (previousData) => previousData,
})
// This is messed up - const query2: UseQueryResult<unknown, unknown>
function keepPreviousData<T>(previousData: T | undefined): T | undefined {
return previousData
}
const query2 = useQuery({
queryKey: [key, count],
queryFn: async () => {
return Promise.resolve(count)
},
placeholderData: keepPreviousData,
}) If i change this type definition from placeholderData?: TQueryData | PlaceholderDataFunction<TQueryData> type NonFunctionGuard<T> = T extends Function ? never : T
placeholderData?: NonFunctionGuard<TQueryData> | PlaceholderDataFunction<NonFunctionGuard<TQueryData>> It works as intended. Therefore i assume that Typescript might be confused cause in What do you think about this solution? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes look good to me - thanks for also using keepPreviousData
internally for our tests 🎉
oh, there are conflicts because of the overloads removal 😅 |
5074d3e
to
291d324
Compare
can you please resolve the conflicts here, too? |
BREAKING CHANGE: removed `keepPreviousData` in favor of `placeholderData` identity function
edc7723
to
25c99ce
Compare
Done ✅ |
# Conflicts: # docs/react/guides/migrating-to-v5.md
Hi @TkDodo ~ Sorry to ask, but my project relies heavily on const query1 = useQuery({
queryKey: [key, count],
queryFn: async () => {
return Promise.resolve(count)
},
placeholderData: (previousData) => previousData,
}) this method instead? |
@jyuloeng yes that's correct. For convenience, you can also do:
it's just an identity function that we are exporting. |
BREAKING CHANGE: removed
keepPreviousData
in favor ofplaceholderData
identity functionCloses: #4688
@TkDodo Questions:
true
? Meaning enabling this behavior by default with option to opt-out? I think we could make that switch later on if we decide to do that.