function Text() {
const [text, setText] = useState("");
return (
<div className="white">
input from which I need to catch information
<input type="text" placeholder="enter" onChange={(e) => setText(e.target.value)} />
<button onClick={console.log(text)}>CLICK</button>
<div>{text}</div>
</div>
);
}
2
Answers
You have to use arrow function in button:
when you put the function like this in
onClick
:This will make it execute each time the component rerender, however :
will make it execute each time the button is clicked