-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[v4][ResourceList.Item] Remove withContext #1503
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
Conversation
958c55c
to
3dd2ec2
Compare
3dd2ec2
to
620be19
Compare
A lot of the lacking coverage has been removed in master with simpler interaction states. So when |
</div> | ||
); | ||
|
||
function handleAnchorFocus() { |
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.
Having a bunch of functions defined beneath the return feels odd to me. Can you pull these up to be towards the start of the function.
This is a functional component and callback functions that we define need to be wrapped in useCallback. Otherwise a new callback function ends up being created every render, and when you pass that down to a child component you end up rerendering it - as its props have changed becase it's onWhatever handler is a different function to the one that was used before.
Wrapping these declarations in useCallback means the same function will be passed to the child component if given the same arguments, thus avoiding unneeded rerenders.
const handleFocusedBlur = useCallback(() => {
setFocusState({focused: true, focusedInner: true});
}, []);
See BPScott/ksw-quiz@30b4c3f for an example of how I dealt with this in my little toy project for playing with react
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 find putting the functions below cleans up the code, Tim does the same as well I think. However, if we use functional expressions we'll want to pull it up. Thanks for pointing this out, I was worried about it but wasn't aware there was a hook to solve it 🙏
620be19
to
c9f5c55
Compare
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.
🎩looks good to me.
c9f5c55
to
8aa2b45
Compare
8aa2b45
to
8c478cf
Compare
WHY are these changes introduced?
Part of #1484
WHAT is this pull request doing?
I'm removing
withContext
in favor of a wrapper componentHow to 🎩
Tests / percy / development server