Skip to content
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

Flip tuple order of useTransition #20976

Merged
merged 1 commit into from Apr 20, 2021

Conversation

rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented Mar 11, 2021

Overview

This PR flips the tuple order of useTransition from:

const [startTransition, isPending] = useTransition();

to

const [isPending, startTransition] = useTransition();

Motivation

The new order, with isPending first nicely mirrors the tuple order of useState and useReducer, where the state value is first and the setter is second. This change makes it easier to remember the correct order, by not needing to remember a difference.

We didn't start the order this way from the beginning because for use cases where the pending value is unused, users would need to use the _ pattern often to denote that the pending value is unused:

const [_, startTransition] = useTransition();

However, since then, we've added React.startTranstion() to work outside of hooks, and this can be used when a pending value is not need. So there's no downside to having the same order as other hooks. And as an added benefit, using the hook version pressures users to do something with the isPending value (like show a spinner on a button), which is considered a best practice.

Closes #17276.

@facebook-github-bot facebook-github-bot added React Core Team Opened by a member of the React Core Team CLA Signed labels Mar 11, 2021
@sizebot
Copy link

sizebot commented Mar 11, 2021

Comparing: cdb6b4c...9b972e5

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 122.80 kB 122.81 kB = 39.44 kB 39.44 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 129.38 kB 129.38 kB = 41.52 kB 41.53 kB
facebook-www/ReactDOM-prod.classic.js +0.01% 412.25 kB 412.29 kB = 76.26 kB 76.27 kB
facebook-www/ReactDOM-prod.modern.js +0.01% 400.32 kB 400.36 kB = 74.36 kB 74.37 kB
facebook-www/ReactDOMForked-prod.classic.js +0.01% 412.25 kB 412.29 kB = 76.26 kB 76.27 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 9b972e5

@rickhanlonii rickhanlonii force-pushed the rh-flip-tuple branch 2 times, most recently from dc3c2fb to 1166cd2 Compare March 11, 2021 04:51
Copy link
Collaborator

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

Yay!

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

Looks good from the DevTools side 👍🏼

@rickhanlonii rickhanlonii merged commit a632f7d into facebook:master Apr 20, 2021
@rickhanlonii rickhanlonii deleted the rh-flip-tuple branch April 20, 2021 16:32
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Apr 22, 2021
Summary:
This diff flips the order of the tuple returned by useTransition.

See here for more info: facebook/react#20976

Changelog: internal

Reviewed By: gaearon

Differential Revision: D27928490

fbshipit-source-id: a1896f92ef24382012fa3be1ef043752e62b21e7
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
@gaearon gaearon mentioned this pull request Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected value order with useTransition
5 participants