【发布时间】:2019-04-28 02:11:43
【问题描述】:
我有以下应用组件:
<Route render={( { location } ) => (
<TransitionGroup component="div" className="content">
<CSSTransition key={location.key} classNames="slide" timeout={{
enter: 1000,
exit: 300
}} appear>
<Switch location={location}>
<Route exact path='/' component={Intro}/>
<Route path="/history" component={History}/>
<Route path="/rules" component={Rules}/>
<Route path="/faq" component={Faq}/>
<Route path="/feedback" component={Feedback}/>
<Route path="/partners" component={Partners}/>
</Switch>
</CSSTransition>
</TransitionGroup>
)}/>
它运行良好,但每个动画都会立即执行。例如,如果我从/rules 转到/history,我会在两个组件上获得完整的动画,但历史组件需要来自服务器的数据,因此动画应用于空容器。
如何在 react-transition-group 组件中暂停动画?我有 Redux,所以我可以在我的应用程序的任何地方更改 loading 变量。另外,我不想在应用启动时预加载商店中的所有数据。
【问题讨论】:
-
何时为新容器获取数据,是否在 componentWillMount 上?
-
@RohitGarg 是的,我试过了。但这并不能解决这个问题,因为获取数据是 Promise(
axios如果这很重要),所以render()将在完成数据加载之前被触发,因此它将触发来自react-transition-group的动画,并在一段时间后出现数据屏幕。
标签: javascript reactjs react-router react-transition-group