react hooks typescirpt父子组件传值类型

elvinyang

关注

阅读 84

2022-02-28

在使用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)

0 0 举报