成帧器运动-状态无法持续通过路线

时间:2020-07-10 05:06:39

标签: reactjs react-router react-hooks react-router-dom framer-motion

我试图使用Framer Motion通过AnimatePresence为路线设置动画,并且由于某些原因,我试图通过每条路线填充信息(通过表单收集个人信息作为注册步骤)的上下文在一个路线中不持久rout退出并通过AnimatePresence加载另一个。我不确定为什么会这样。每次加载新路线时,我都应该将状态作为道具吗?

 <AnimatePresence exitBeforeEnter>
   <Switch location={location} key={location.key}>
      <Route exact path="/" component={LandingPage} />
      ...
    </Switch>
 </AnimatePresence>

我已经为每个路线中的每个组件添加了初始,动画和退出过渡。一旦一个组件退出并承担其他负载,存储在上下文中的状态就会重置。

这里location来自const location = useLocation()的{​​{1}}

1 个答案:

答案 0 :(得分:0)

我想我明白了。将您的上下文提供程序放在AnimatePresence内将重新加载其中的框架,从而导致刷新状态。