admin管理员组文章数量:1406951
After installing framer motion and applying some animations to my NextJS component, I get error,
[Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
import { motion } from "framer-motion";
const HeroSection: React.FC = () => {
return (
<div className="text-white py-10 overflow-hidden">
<div className="container mx-auto px-6 flex flex-col lg:flex-row items-center">
<motion.div
className="w-full lg:w-3/5 mb-12 lg:mb-0"
initial={{ opacity: 0, x: -50 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.6, ease: "easeOut" }}
>
</motion.div>
</div>
</div>
);
};
export default HeroSection;
After installing framer motion and applying some animations to my NextJS component, I get error,
[Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
import { motion } from "framer-motion";
const HeroSection: React.FC = () => {
return (
<div className="text-white py-10 overflow-hidden">
<div className="container mx-auto px-6 flex flex-col lg:flex-row items-center">
<motion.div
className="w-full lg:w-3/5 mb-12 lg:mb-0"
initial={{ opacity: 0, x: -50 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.6, ease: "easeOut" }}
>
</motion.div>
</div>
</div>
);
};
export default HeroSection;
Share
Improve this question
asked Mar 4 at 10:08
oyerohabiboyerohabib
3956 silver badges20 bronze badges
1 Answer
Reset to default 0I figured out that framer could only work in a client-based component and since I was using NextJS, I had to add the "use client" directive at the top, which fixed the issue.
"use client"
import { motion } from "framer-motion";
const HeroSection: React.FC = () => {
return (
<div className="text-white py-10 overflow-hidden">
<div className="container mx-auto px-6 flex flex-col lg:flex-row items-center">
<motion.div
className="w-full lg:w-3/5 mb-12 lg:mb-0"
initial={{ opacity: 0, x: -50 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.6, ease: "easeOut" }}
>
</motion.div>
</div>
</div>
);
};
export default HeroSection;
本文标签:
版权声明:本文标题:javascript - Framer [Error: Element type is invalid: expected a string (for built-in components) or a classfunction (for composi 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745051581a2639687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论