I am facing problem while updating check box state using React hooks, By default check box is false.
Below code sample
function GPSPosition() {
const [isEnable, setCheckBoxEnable] = useState(false)
const enableStopSendingData = (e) => {
e.preventDefault();
setCheckBoxEnable(e.target.checked)
console.log(e.target.checked);// on check of CheckBox, here value is `true`
console.log(isEnable); // true is not set to isEnable, value here is `false`
}
return (
<div className="text-ellipsis">{GpsConstants.WIDGET_NAME}</div>
<Checkbox checked={isEnable} onChange={(checked) => enableStopSendingData(checked)}
className="homepage-widget-checkbox text-ellipsis" >{HomepageConst.CHECKBOX_HEADER}
</Checkbox>
</div>
)
}