最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Framer [Error: Element type is invalid: expected a string (for built-in components) or a classfunction (for composi

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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;

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论