close

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

Today We are Going To Solve Type ‘void’ is not assignable to type ((event: MouseEvent) => void) | undefined in javascript. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

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

  1. How to Fix Type ‘void’ is not assignable to type ((event: MouseEvent) => void) | undefined Error?

    To Fix Type ‘void’ is not assignable to type ((event: MouseEvent) => void) | undefined Error just Assign this.fetchData(“dfd”)} to onClick. o solve this error assign this.fetchData(“dfd”)} to onClick. By assigning it, The core will not returns voidvoid and you can solve your error easily. So just try this method.

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

    To Fix Type ‘void’ is not assignable to type ((event: MouseEvent) => void) | undefined Error just Use React.MouseEvent. Here you have to use React.MouseEvent with functional components. BY using this you can solve your error. So just try this as I have given in the below example. const clickHandler = () => { return (event: React.MouseEvent) => { ...do something... event.preventDefault(); } }

Solution 1 : Assign this.fetchData(“dfd”)} to onClick.

To solve this error assign this.fetchData(“dfd”)} to onClick. By assigning it, The core will not returns voidvoid and you can solve your error easily. So just try this method.

Solution 2 : Use React.MouseEvent

Here you have to use React.MouseEvent with functional components. BY using this you can solve your error. So just try this as I have given in the below example.

const clickHandler = () => {
  return (event: React.MouseEvent) => {
    ...do something...
    event.preventDefault();
  }
}

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read This Solutions

Leave a Comment