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

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

Fix

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

More Information

This is a very common error prevented by TypeScript 🌹

Leave a Comment