0
点赞
收藏
分享

微信扫一扫

react hooks typescirpt父子组件传值类型

elvinyang 2022-02-28 阅读 84

在使用typescript中,遇到父子组件传方法时,类型不匹配,记录下如何写类型。
父组件

export default function Learn() {
  const [wordCount, setWordCount] = useState(0);

  return (
    <Box>
      <Appbar setWordCount={setWordCount} />
      <Link to="/">首页</Link>
      learn
    </Box>
  );
}

子组件

export interface MyAppBarProps {
  setWordCount: (x: number) => void;
}

function Myappbar(props: MyAppBarProps) {
  const { setWordCount } = props;
  }
举报

相关推荐

0 条评论