-
Notifications
You must be signed in to change notification settings - Fork 1.3k
chore: Update eslint plugin react hooks #9012
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
base: main
Are you sure you want to change the base?
Conversation
Build successful! 🎉 |
The linter is probably correct about the errors with our useEffectEvent. We should try to solve those instead of renaming the hook. |
Darn, just a gut feeling? Or is there something in particular you're worried about? Trying to understand the rules better |
Child effects run before parents so the function won't necessarily be bound yet if you pass one down |
Ok, so nothing beyond what I noted in the description, which we don't currently violate from what I saw. Will explore some fixes this week. |
This reverts commit 7b96414.
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
removeGlobalListener(window, 'pointerup', onPointerUp, false); | ||
removeGlobalListener(window, 'pointercancel', onPointerUp, false); | ||
}; | ||
} else if (pointerDown === 'mouse' && process.env.NODE_ENV === 'test') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically these can only happen during test environment, but i've added here so that the dead code remover knows to get rid of it
Build successful! 🎉 |
## API Changes
@react-aria/utils/@react-aria/utils:useUpdateEffect useUpdateEffect {
- effect: EffectCallback
+ cb: EffectCallback
dependencies: Array<any>
returnVal: undefined
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to come back to the usePress change (I think it is mainly just code moving around), but my comment on the useAutocomplete change encompasses my main thoughts about the change, primarily a slight concern around move away from using useEffectEvent since they are scoped to useEffectEvents/useEffects within the same component by the linter, but that means things that used to be returned from various hooks are now reactive again. Maybe a nothing burger
}, []); | ||
|
||
let updateActiveDescendant = useEffectEvent((e: Event) => { | ||
let updateActiveDescendant = useCallback((e: Event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure I understand this update here. This would mean the callbackRef below now will become reactive to changes in state/shouldVirtualFocus and thus remove and re-add the event listener every time the user types/moves virtual focus. However, if we use useEffectEvent
we only need to attach the listener once and we will still get up to date values in this call.
I guess this is because of reactjs/react.dev#8075 (comment) and on where this may become a potential pitfall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another option, I could set a state as a result of the callback ref when the component mounts. Then in an effect I could attach the listener instead. Then I can use this an an effect event again. I was opting for less renders, but it does mean detach and reattach
Closes
Updates to the latest eslint plugin for react to use the compiler. The main transforms I applied are detailed in this issue Confusion with useEffectEvent lint rules
Note, I had to use useLayoutEffect to get the synchronous behaviour in React 16 and 17 so that events fired back to back would still have the effect run between them. (for example,
This could also be accomplished with flushSync, but then that takes us out of concurrent mode.
This PR mostly focuses on
react-hooks/rules-of-hooks
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: