typescript 打字脚本属性转换为javascript属性

bihw5rsg  于 2022-11-18  发布在  TypeScript
关注(0)|答案(1)|浏览(143)

**我需要在 javascript 文件中使用此directionLeft。当前在 typescript 文件中。我需要知道如何在JSX文件中传递这些属性。 请帮助我完成此操作。

import React from "react";
    import { motion } from "framer-motion";
    import image from "../public/img/me.jpg";
    import Image from "next/image";
    
    type props = {
        directionLeft?: Boolean;
    }
    
    function Skill({directionLeft}: props) {
      return (
        <div className="group relative flex cursor-pointer">
          <motion.div
            initial={{
              x: directionLeft ? -200 : 200,
              opacity: 0,
            }}
            transition={{ duration: 1 }}
            whileInView={{
              opacity: 1,
              x: 0,
            }}
          >
            <Image
              src={image}
              className="rounded-full border"/>
          </motion.div>
        </div>
      );
    }
    
    export default Skill;
to94eoyn

to94eoyn1#

您可以在JSX文件中简单地使用它:

import React from "react";
    import { motion } from "framer-motion";
    import image from "../public/img/me.jpg";
    import Image from "next/image";
    
    function Skill({directionLeft}) {
      return (
        <div className="group relative flex cursor-pointer">
          <motion.div
            initial={{
              x: directionLeft ? -200 : 200,
              opacity: 0,
            }}
            transition={{ duration: 1 }}
            whileInView={{
              opacity: 1,
              x: 0,
            }}
          >
            <Image
              src={image}
              className="rounded-full border"/>
          </motion.div>
        </div>
      );
    }
    
    export default Skill;

相关问题