Skip to content

Commit

Permalink
Consider dispatch from useActionState and useFormState stable
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 30, 2024
1 parent b024f7e commit 1e97088
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export default {
// ^^^ true for this reference
// const [state, dispatch] = useReducer() / React.useReducer()
// ^^^ true for this reference
// const [state, dispatch] = useActionState() / React.useActionState()
// ^^^ true for this reference
// const [state, dispatch] = useFormState() / ReactDOM.useFormState()
// ^^^ true for this reference
// const ref = useRef()
// ^^^ true for this reference
// const onStuff = useEffectEvent(() => {})
Expand Down Expand Up @@ -232,10 +236,11 @@ export default {
return false;
}
let callee = init.callee;
// Step into `= React.something` initializer.
// Step into `= React(DOM).something` initializer.
if (
callee.type === 'MemberExpression' &&
callee.object.name === 'React' &&
(callee.object.name === 'React' ||
callee.object.name === 'ReactDOM') &&
callee.property != null &&
!callee.computed
) {
Expand All @@ -260,7 +265,12 @@ export default {
}
// useEffectEvent() return value is always unstable.
return true;
} else if (name === 'useState' || name === 'useReducer') {
} else if (
name === 'useState' ||
name === 'useReducer' ||
name === 'useFormState' ||
name === 'useActionState'
) {
// Only consider second value in initializing tuple stable.
if (
id.type === 'ArrayPattern' &&
Expand Down

0 comments on commit 1e97088

Please sign in to comment.