Skip to content

Commit

Permalink
fix(taro-components): 修复定时器在组件更新时未取消问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zsir authored Mar 6, 2020
1 parent 11b0026 commit 291feae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/taro-components/src/components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class Button extends Nerv.Component {
touch: false
}
}

componentWillUnmount() {
this.startTimer && clearTimeout(this.startTimer)
this.endTimer && clearTimeout(this.endTimer)
}

render () {
const {
Expand Down Expand Up @@ -48,7 +53,7 @@ class Button extends Nerv.Component {
touch: true
}))
if (hoverClass && hoverClass !== 'none' && !disabled) {
setTimeout(() => {
this.startTimer = setTimeout(() => {
if (this.state.touch) {
this.setState(() => ({
hover: true
Expand All @@ -63,7 +68,7 @@ class Button extends Nerv.Component {
touch: false
}))
if (hoverClass && hoverClass !== 'none' && !disabled) {
setTimeout(() => {
this.endTimer = setTimeout(() => {
if (!this.state.touch) {
this.setState(() => ({
hover: false
Expand Down

0 comments on commit 291feae

Please sign in to comment.