【发布时间】:2021-01-04 20:25:40
【问题描述】:
我有一个在两个组件之间切换的按钮。 如何在退出时为每个组件添加动画?这是我的代码不起作用:
export default function App() {
const [dark, setDark] = useState(false);
const toggle = () => {
setDark(!dark);
};
return (
<div>
<AnimatePresence>
{dark ? (
<motion.h2 exit={{ opacity: 0 }}>Dark</motion.h2>
) : (
<motion.h2 exit={{ opacity: 0 }}>Light</motion.h2>
)}
</AnimatePresence>
<button onClick={toggle}>Toggle</button>
</div>
);
}
感谢您的帮助!
【问题讨论】:
标签: javascript reactjs framer-motion