DEV Community

Cover image for Motion & color keywords don’t mix.
Alesei N
Alesei N

Posted on

Motion & color keywords don’t mix.

At least as it stands now.

Kind of makes sense, but if you stumble for a bit, maybe this helps you save 10–15 minutes of your time.

❌ Don’t

<motion.div
  initial={{ backgroundColor: "white" }}
  animate={{ backgroundColor: "black" }}
  transition={{ duration: 3, repeat: Infinity, repeatType: "reverse" }}
  style={{ width: "10em", height: "10em" }}
/>
Enter fullscreen mode Exit fullscreen mode

✅ Do

<motion.div
  initial={{ backgroundColor: "#FFFFFF" }}
  animate={{ backgroundColor: "#000000" }}
  transition={{ duration: 3, repeat: Infinity, repeatType: "reverse" }}
  style={{ width: "10em", height: "10em" }}
/>
Enter fullscreen mode Exit fullscreen mode

Also

Style prop css values will not be used as initial values… You are welcome.


motion #animation #react #javascript

Top comments (0)