I am learning react.js functional components and I came with the method useState()
. Which gives an array in return [currentState, stateSetter]
. Now if we use stateSetter()
in an event. And we know that events are called differently. So how does it access the handleClick()
function. Since it is not defined inside the scope?
import React, {useState} from 'react';
function App(props) {
const [name, setName] = useState("name1");
const handleClick = () => {
setName("name2");
}
return (
<div>
<p>Hello, {name}</p>
<button onClick = {handleClick}></button>
</div>
)
}