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

[exhaustive-deps] Add startTransition as a known stable method #19720

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ const tests = {
const [state4, dispatch2] = React.useReducer();
const [state5, maybeSetState] = useFunnyState();
const [state6, maybeDispatch] = useFunnyReducer();
const [startTransition1] = useTransition();
const [startTransition2, isPending2] = useTransition();
const [startTransition3] = React.useTransition();
const [startTransition4, isPending4] = React.useTransition();
const mySetState = useCallback(() => {}, []);
let myDispatch = useCallback(() => {}, []);

Expand All @@ -616,6 +620,10 @@ const tests = {
setState2();
dispatch1();
dispatch2();
startTransition1();
startTransition2();
startTransition3();
startTransition4();

// Dynamic
console.log(state1);
Expand All @@ -624,6 +632,8 @@ const tests = {
console.log(state4);
console.log(state5);
console.log(state6);
console.log(isPending2);
console.log(isPending4);
mySetState();
myDispatch();

Expand All @@ -634,6 +644,7 @@ const tests = {
// Dynamic
state1, state2, state3, state4, state5, state6,
maybeRef1, maybeRef2,
isPending2, isPending4,

// Not sure; assume dynamic
mySetState, myDispatch,
Expand Down
11 changes: 11 additions & 0 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ export default {
return false;
}
}
} else if (name === 'useTransition') {
if (
id.type === 'ArrayPattern' &&
Array.isArray(resolved.identifiers)
) {
// Is first tuple value the same reference we're checking?
if (id.elements[0] === resolved.identifiers[0]) {
// Setter is stable.
return true;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wasn't sure if I should add isPending to the stateVariables set.

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 copy-pasted the block above for useState and useReducer and tweaked it

}
}
// By default assume it's dynamic.
return false;
Expand Down