Type 'void' is not assignable to type '((event: MouseEvent) => void) | undefined'

后端 未结 5 1719
花落未央
花落未央 2020-12-24 11:06
   import * as React from \"react\";
   import \"./App.css\";
   import PageTwo from \"./components/PageTwo\";

    export interface IPropsk {
        data?: Array&l         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 11:21

    In your code this.fetchData("dfd") you are calling the function. The function returns void. void is not assingable to onClick which expects a function.

    Fix

    Create a new function that calls fetchData e.g. onClick={() => this.fetchData("dfd")}.

    More

    This is a very common error prevented by TypeScript

提交回复
热议问题