-
Notifications
You must be signed in to change notification settings - Fork 3
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
Reduce Tabs component re-renders and fix controlled component functionality #31
base: master
Are you sure you want to change the base?
Conversation
onTabChange(item) | ||
} | ||
}, | ||
[onTabChange] |
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.
shouldn't item
also be included in the dependencies here? just in case it were to change?
isActive={selectedTab === item.label} | ||
key={index} | ||
item={item} | ||
onTabChange={() => handleTabChange(item)} |
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.
to avoid having this be an inline anonymous function, which can effect re-renders, I think you can just make this onTabChange={handleTabChange}
, because when you call it now from within the Tab
component, you send the item
as an argument there, which the function definition is equipped to handle
@@ -22,12 +30,33 @@ export const Normal = ({ themeName }) => { | |||
|
|||
return ( | |||
<> | |||
<Tabs | |||
<FormCheckbox |
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.
This is a good idea, but should be governed as a story "Knob", rather than an on page element. See the componentKnobs
of other stories like FormInput
Various optimizations and
<Tab />
component tree isolation to reduce renders and re-mounts.Adds a checkbox and proper state to the story to show the component working as a controlled component.