For some reason, even though it seems to work elsewhere, I'm trying to do a simple radio button form and it does not render the updated selection. The state is set up appropriately, however the UI does not show the change. When I update the code and the browser updates the app, for some reason it keeps the current state, and it does actually display the radio button selected. But if I select another radio button, even though the state is changing, the UI still displays the same radio button as before.
I don't know if this makes a difference but this is my react version "react": "17.0.2",.
I'm also using a functional component.
Here's the code:
const [radioState2, setRadioState2] = useState(0);
const setRadioState2Handler = (event) => {
console.log("setRadioState2Handler()");
console.log("event");
console.log(event);
console.log("event.target.value");
console.log(event.target.value);
console.log(typeof event.target.value);
setRadioState2(parseInt(event.target.value));
};
<div>
<form>
<input type="radio" name="radioform2" value="1" checked={radioState2===1 } onChange={setRadioState2Handler} />{" "} radio <br />
<input type="radio" name="radioform2" value="2" checked={radioState2===2 } onChange={setRadioState2Handler} />{" "} radio <br />
<input type="radio" name="radioform2" value="3" checked={radioState2===3 } onChange={setRadioState2Handler} />{" "} radio <br />
</form>
</div>
Thanks in advance