Skip to content

Conversation

@TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Apr 28, 2021

still missing:

  • documentation

@vercel
Copy link

vercel bot commented Apr 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/EauHPTxmP8XGSQxuYLttSDo2mvm3
✅ Preview: https://react-query-git-fork-tkdodo-feature-setqueriesdata-ta-dee3b1.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 28, 2021

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 95bed80:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

filters: QueryFilters,
updater: Updater<TData | undefined, TData>,
options?: SetDataOptions
): [QueryKey, TData][]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is the best return type - wanted to provide a way to show which key actually had data set, as calling setQueriesData on a filter that doesn't match anything will not set anything

.findAll(queryKeyOrFilters)
.map(({ queryKey }) => [
queryKey,
this.setQueryData<TData>(queryKey, updater, options),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boschni I'm a bit worried that calling setQueryData multiple times in a row triggers multiple re-renders, and it does. see this example, where onButtonClick, I call setQueryData three times for three queries, and even though it's synchronous, it will trigger 3 re-renders:

https://codesandbox.io/s/tannerlinsleyreact-query-basic-forked-5c6rs?file=/src/index.js

I tried to wrap it in notifyManager.batchCalls, but it didn't change anything.

This is not much to do with this PR, but because I'm now calling setQueryData in a loop, it might show :)

Do you have any idea how to batch these calls maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't find this out, but is also not so important I guess. if we get the api of that function right, we can always optimize it internally later :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @TkDodo! The entire function body should be wrapped in notifyManager.batch, this should prevent redundant renders

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you 🙏 , seems like I messed up batchCalls and batch 😅 . fixed it here: 95bed80

.setData(updater, options)
}

setQueriesData<TData>(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are not creating queries like with setQueryData, because we only update matching keys, would updateQueries or updateQueriesData be a better name?

this was also mentioned by @tannerlinsley here: #135 (comment)

but I don't think it made it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current name is fine as long as people realize that it will not create queries.

@TkDodo TkDodo marked this pull request as ready for review April 30, 2021 10:15
@TkDodo TkDodo requested a review from tannerlinsley April 30, 2021 10:15
Comment on lines +132 to +133
setQueriesData<TData>(
filters: QueryFilters,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't create an overload that accepts queryKey and filters, even though some other functions have this, because the updater is required so the signature would be very weird. I also don't think it's important because the filters also have the option to pass a queryKey.

wrap setQueriesData in notifyManager.batch to avoid unnecessary re-renders
@tannerlinsley
Copy link
Member

🎉 This PR is included in version 3.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@TkDodo TkDodo deleted the feature/setQueriesData branch May 8, 2021 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants