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

Reduce Tabs component re-renders and fix controlled component functionality #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

coreyafunk
Copy link

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.

onTabChange(item)
}
},
[onTabChange]
Copy link
Contributor

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)}
Copy link
Contributor

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants