I need to show a component with fade in or fade out and hide it altogether, depending on the property value (true or false).
class Tooltip extends Component {
constructor(props) {
super(props);
this.state = {visible: false};
}
componentWillReceiveProps(newProps) {
if (newProps.status === true) {
this.setState({visible: newProps.status});
} else {
this.setState({visible: false});
}
}
render() {
return (
<div className={"fade" + ( this.state.visible === true ? ' in' : '' ) + " tooltip tooltip-danger"}>
<div className="text">{this.props.text}</div>
</div>
);
}
}
Everything works well, the component appears and disappears smoothly, but is not removed from the output.
And I need to completely remove the component after smoothly hiding.
I try to change the code a little, but in this case the component is removed from the output, but the fade-in and fade-out effects disappear ...
class Tooltip extends Component {
constructor(props) {
super(props);
this.state = {visible: false};
}
componentWillReceiveProps(newProps) {
if (newProps.status === true) {
this.setState({visible: newProps.status});
} else {
this.setState({visible: false});
}
}
render() {
if (this.state.visible === false) {
return null;
}
return (
<div className={"fade" + ( this.state.visible === true ? ' in' : '' ) + " tooltip tooltip-danger"}>
<div className="text">{this.props.text}</div>
</div>
);
}
}
Please, help me! Thank you!