Issue
Can anyone please explain to me why when I run this code I got this error : App.js:11 Uncaught ReferenceError: handleClick is not defined.the code in question
but when I changed it to the code below it workedthe code that works
Solution
in the first case, you are using a function component and this inside function component is undefined, so when you call the function using this.handleClick() it gives you a reference error.
But at the same time in the class component, it works because this refers to the object, which is an instance of the class Component
You need to move handleClick to the component function.
export default function App() {
const handleClick = () => { ... }
...
}
Answered By - Mridul Gupta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.