I want to see the changes in the use of react hooks on state immediately. My changes are one step behind on state. How can I solve this.
const [categoryID, setCategoryID] = useState(0);
const changeCategory = (e) => {
setCategoryID(e.target.value);
console.log(categoryID);
};
<Field
as="select"
onChange={changeCategory}
style={formStyle().inputStyle}
className="form-control"
type="text"
name="categoryID"
>
When I select the first value, the result appears 0. If I chose my second value, I see the value I chose first on the console.