What happens to a function when a component re-renders in react? Is it recreated everytime?
export default function App() {
console.log("rendered");
const [isOpen, setisOpen] = useState(false);
function handleClick() {
setisOpen(true);
}
return (
<div className="App">
<button onClick={handleClick}>Click</button>
{isOpen && <div>Secret is opened.</div>}
</div>
);
}
Why does this component renders 3 times?
handleClickwill be re-created.