I am new to React. I am just playing around with passing values around. I am confused what I am doing wrong with the button click. I want that to check the value from the input and to generate a random number. Here is my code:
export default function Random() {
const [state, setState] = useState({
start: "",
final: ""
});
let handleClick = (e) => {
setState({
start: e.target.value,
final: Math.floor(Math.random() * state.start) + 1
});
};
return (
<div>
<h1>Randomizer based off your number</h1>
<input onChange={handleClick} type="number" />
<button onClick={handleClick}>Random number</button>
<h4>{`You entered ${state.start} and the random number is ${state.final}`}</h4>
</div>
);
}