gpt4 book ai didi

javascript - ReactCSSTransitionGroup componentWillLeave 未调用

转载 作者:搜寻专家 更新时间:2023-11-01 04:30:16 28 4
gpt4 key购买 nike

我正在尝试使用 ReactCssTransition,但不知何故事件未被调用(componentWillLeave)

这是我的组件

import React, { Component } from 'react'
import TransitionGroup from 'react-addons-css-transition-group'

export default class TransitionComponent extends Component {

constructor(props) {
super(props);
}

render() {
return (
let {componentKey} = this.props
<TransitionGroup transitionName="example" transitionEnterTimeout={500} transitionLeaveTimeout={500}>
<Item key={"item"+componentKey} />
</TransitionGroup>
);
}
}

和子组件

class Item extends Component {

componentDidEnter() {
console.log("component did enter");
}

componentWillLeave(callback) {
console.log("component will leave");
}

render() {
return (
<div>Item</div>
)
}
}

有什么线索吗?谢谢!

最佳答案

由于没有在“componentWillEnter”函数中调用回调,我遇到了类似的问题。引自 React documentation

It will block other animations from occurring until callback is called

class Item extends Component {

componentWillEnter(callback) {
console.log("component will enter");
callback();
}

componentDidEnter() {
console.log("component did enter");
}

componentWillLeave(callback) {
console.log("component will leave");
callback();
}

render() {
return (
<div>Item</div>
)
}
}

关于javascript - ReactCSSTransitionGroup componentWillLeave 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35803344/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com