Skip to content

Commit 380da26

Browse files
committed
Fix #361 cancel timer when tabs component unmounts
1 parent 752f2cb commit 380da26

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

components/tabs/Tabs.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class Tabs extends React.Component {
2727
this.updatePointer(nextProps.index);
2828
}
2929

30+
componentWillUnmount () {
31+
clearTimeout(this.pointerTimeout);
32+
}
33+
3034
handleHeaderClick = (idx) => {
3135
if (this.props.onChange) this.props.onChange(idx);
3236
};
@@ -50,7 +54,8 @@ class Tabs extends React.Component {
5054
}
5155

5256
updatePointer (idx) {
53-
setTimeout(() => {
57+
clearTimeout(this.pointerTimeout);
58+
this.pointerTimeout = setTimeout(() => {
5459
const startPoint = this.refs.tabs.getBoundingClientRect().left;
5560
const label = this.refs.navigation.children[idx].getBoundingClientRect();
5661
this.setState({

0 commit comments

Comments
 (0)