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.
Contents
How to Fix Type ‘void’ is not assignable to type ((event: MouseEvent) => void) | undefined Error?
- 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 Create a new function. Here to solve this error you have to create a new function that calls fetchData. You can better understand this by giving the below example:
onClick={() => this.fetchData("dfd")}
- 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
. To solve the error you have to just useReact.MouseEvent
. You can use it in the way given in the below code. So just try this.const clickHandler = () => { return (event: React.MouseEvent) => { ...do stuff... event.preventDefault(); } }
Solution 1 : Create a new function
Here to solve this error you have to create a new function that calls fetchData. You can better understand this by giving the below example:
onClick={() => this.fetchData("dfd")}
Solution 2 : Use React.MouseEvent
To solve the error you have to just use React.MouseEvent
. You can use it in the way given in the below code. So just try this.
const clickHandler = () => {
return (event: React.MouseEvent) => {
...do stuff...
event.preventDefault();
}
}
Solution 3 : Use the correct way
Just change
button.onclick = thisFunction();
to
button.onclick = thisFunction;
Because that is the correct way and it will help you.
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 These Solutions
- UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xe9 in position 10: invalid continuation byte
- Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist
- How to downgrade python version from 3.9 to 3.8
- ImportError: No module named ‘yaml’
- Fatal error in launcher: Unable to create process using ‘”‘