Member-only story
Coding Chronicles #3 | React TypeScript onClick | Expected `onClick` listener to be a function, instead got a value of `object` type.
onClick event expects a reference to the function.
A usual day in the life of a software programmer brings out many coding challenges. Most of these challenges need a few minutes of online search. I started a series of mini blogs dealing with some of these challenges a few days back. The complexity of these challenges will range from average to complex.
This article addresses a React TypeScript issue following previous articles on Playwright problems.
Use Case
I am currently writing an upload functionality. A bin icon is present next to each file. With the click of the bin Icon, a type script method calls a GraphQl API. The GraphQl API handles the file deletion logic.
I don’t have much experience with React. Hence, I started reading about the onclick event listener.
The first solution I got was:
onClick={handleDeleteFileClick(fileName)}: