Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

selectFromResult for mutations #206

Merged
merged 8 commits into from
Apr 18, 2021
Merged

selectFromResult for mutations #206

merged 8 commits into from
Apr 18, 2021

Conversation

msutkowski
Copy link
Member

@msutkowski msutkowski commented Apr 16, 2021

  • Adds selectFromResult option for useMutation().
    • This allows a user to 'optimize renders' by only rerendering when the selected values change. There will always be 1 rerender when the mutation is called as it creates a new requestId. For the most performant implementation, you can yourEndpoint.useMutation(undefined, { selectFromResult: () => ({}) })
    • All possible usages can be seen in the tests with the appropriate assertions 😅

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 16, 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 f075099:

Sandbox Source
React Configuration
React Typescript Configuration
svelte-app-rtk-simplequery-demo Configuration

@msutkowski msutkowski marked this pull request as ready for review April 16, 2021 18:14
@msutkowski msutkowski added this to the 0.3.0 milestone Apr 16, 2021
@github-actions
Copy link

github-actions bot commented Apr 16, 2021

size-limit report 📦

Path Size
ESM full 10.15 KB (0%)
ESM full (React) 11.56 KB (+0.16% 🔺)
createApi + setupListeners 9.19 KB (0%)
createApi (React) + setupListeners 10.46 KB (+0.23% 🔺)
fetchBaseQuery 701 B (0%)
retry 278 B (0%)
ApiProvider 400 B (0%)
CJS minfied 15.67 KB (0%)
CJS React minfied 17.37 KB (+0.22% 🔺)

@msutkowski msutkowski force-pushed the mutation-selectFromResult branch 2 times, most recently from 6f305a4 to cd1a655 Compare April 17, 2021 02:56
Copy link
Member Author

@msutkowski msutkowski left a comment

Choose a reason for hiding this comment

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

This change will require updates in the docs that were merged: https://github.com/rtk-incubator/rtk-query/pull/191/files#diff-b2cf37354c870ebf35a4045446fae1006ca83193784282bb2066da6bba8a1f91R94, but was introduced for consistency with the other hook names

Copy link
Collaborator

@phryneas phryneas left a comment

Choose a reason for hiding this comment

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

Already said it in chat - I think we don't need the fancy type overloading here as we don't really have a use for isFetching in mutations.

My change suggestions might be a bit sloppy, I'm not feeling so well 🙃

src/react-hooks/buildHooks.ts Outdated Show resolved Hide resolved
src/react-hooks/buildHooks.ts Outdated Show resolved Hide resolved
src/react-hooks/buildHooks.ts Outdated Show resolved Hide resolved
src/react-hooks/buildHooks.ts Outdated Show resolved Hide resolved
src/react-hooks/buildHooks.ts Outdated Show resolved Hide resolved
test/buildHooks.test.tsx Outdated Show resolved Hide resolved
msutkowski and others added 2 commits April 18, 2021 09:10
Co-authored-by: Lenz Weber <mail@lenzw.de>
Copy link
Collaborator

@phryneas phryneas left a comment

Choose a reason for hiding this comment

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

mini nitpicks, then this can go in :)

src/core/buildSelectors.ts Outdated Show resolved Hide resolved
src/react-hooks/buildHooks.ts Outdated Show resolved Hide resolved
Co-authored-by: Lenz Weber <mail@lenzw.de>
@netlify
Copy link

netlify bot commented Apr 18, 2021

Deploy preview for rtk-query-docs ready!

Built with commit f075099

https://deploy-preview-206--rtk-query-docs.netlify.app

@msutkowski msutkowski merged commit b501095 into next Apr 18, 2021
@msutkowski msutkowski deleted the mutation-selectFromResult branch April 18, 2021 21:31
msutkowski added a commit that referenced this pull request Apr 18, 2021
* Add selectFromResult as an option to the useMutation hook
* Update UseMutation return type and tests

Co-authored-by: Lenz Weber <mail@lenzw.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I want a selector like react-redux for optimize the number of renders.
3 participants