Skip to content
This repository was archived by the owner on Oct 19, 2021. It is now read-only.

Commit 2335c44

Browse files
authored
fix(Tabs): avoid stale tab ref cache (#2224)
The problem happens when `selected` and `children` changes at the same time. Fixes #2204.
1 parent 4bb5cb9 commit 2335c44

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/components/Tabs/Tabs.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ export default class Tabs extends React.Component {
115115
return React.Children.map(this.props.children, tab => tab);
116116
}
117117

118-
getTabAt = index => {
118+
getTabAt = (index, useFresh) => {
119119
return (
120-
this[`tab${index}`] || React.Children.toArray(this.props.children)[index]
120+
(!useFresh && this[`tab${index}`]) ||
121+
React.Children.toArray(this.props.children)[index]
121122
);
122123
};
123124

@@ -251,7 +252,7 @@ export default class Tabs extends React.Component {
251252
}),
252253
};
253254

254-
const selectedTab = this.getTabAt(this.state.selected);
255+
const selectedTab = this.getTabAt(this.state.selected, true);
255256
const selectedLabel = selectedTab ? selectedTab.props.label : '';
256257

257258
return (

0 commit comments

Comments
 (0)