reactjs - 退出转换未触发 React Reveal
问题描述
我正在使用 React Reveal 实现滑入/滑出过渡,特别是https://www.react-reveal.com/examples/common/slide/,如下所示。
加载项目组件时会触发动画中的幻灯片,但是当我转到其他路线时,它不会触发退出动画。
import Slide from 'react-reveal/Slide';
class SlideExample extends React.Component {
constructor(props) {
super(props);
this.state = { show: false };
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState({ show: !this.state.show });
}
render() {
return (
<div>
<Slide left opposite when={this.state.show}>
<h1>React Reveal</h1>
</Slide>
<button
className="btn btn-success my-5"
type="button"
onClick={this.handleClick}
>
{ this.state.show ? 'Hide' : 'Show' } Message
</button>
</div>
);
}
}
export default SlideExample;
这是我的代码:
导航栏组件:
//state and handleClick function
const [transition, setTransition] = useState(false);
const [show, setShow] = useState(false);
const activeCircle = useRef();
const handleClick = (color, route) => {
activeCircle.current = color;
setTransition(!transition);
setShow(!show);
setTimeout(() => {
color === "black"
? props.history.push("/")
: props.history.push(`/${route}`);
}, 1000);
};
//div where show is being passed
<div
style={activeCircle.current === "blue" ? style : {}}
className={`blueCircle ${transitionActive1}`}
onClick={() => handleClick("blue", "projects")}
show={show}
></div>
项目组件(在此处通过转换):
<Slide top opposite when={props.show}>
<div className="pleftColumn">
<h1>Left Column</h1>
</div>
</Slide>
解决方案
推荐阅读
- xpath - 需要使用 Xpath 解析 XML 中的连接字符串
- docker - Dockerfile目录位置在wondows 8.1中
- android-studio - OkHttpClient ExceptionInInitializerError
- java - 将 application.properties 传递给 Logback 自定义过滤器
- python - 如何将包导入循环到函数定义中?
- aws-lambda - 如何使用 serverless.yml 使用通用 DynamoDB 流触发 aws lambda 函数
- python - 为什么我的 matplotlib 直方图没有在 PyCharm 中从 Tweepy 获取的数据中绘制?
- php - 将终端进程作为后台进程运行
- excel - 有没有办法以编程方式确定是否在 VBA 中打开了错误处理?
- linux - 如何在 Linux Ubuntu 中连接以太网?