Replies: 1 comment
-
Your code doesn't work because you trying to animate You can use export default function Home() {
const MotionBox = motion(Box);
const [isActive, setActive] = useState(false);
const active = {
initial: {
x: 20
},
animate: {
x: 0
}
};
const inactive = {
initial: {
x: 0
},
animate: {
x: 20
}
};
return (
<MotionBox
h="50px"
w="150px"
bgColor="red"
mb=".75rem"
initial="initial"
animate="animate"
variants={isActive ? active : inactive}
onClick={() => {
setActive(!isActive);
}}
>
Move
</MotionBox>
);
} https://codesandbox.io/s/zen-drake-5c196?file=/pages/index.jsx |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi
I want to create a component that when you click on it it moves to the right, click again and it returns to its initial position.
I can get it to work if I use <motion.div> but if I use MotionBox (as below) it slides right then on second click jumps back it's initial position, not slides. Assume due to a re-render.
How do I solve this?
TIA
Beta Was this translation helpful? Give feedback.
All reactions