I am trying to pass the updated value through convert function to display the new result on every state update but it seems the states "const [values]" is not updating immediately and I am getting results from previous state value. So with every value change my results are a step behind. In the console I can see I am getting new value from the input but the "values" state shows previous values.
const [values, setValues] = useState({
sqmtr: "",
sqft: "",
});
const handleTextChange = (text, name) => {
setValues({ ...values, [name]: text });
convert(unit, values);
console.log(text);
console.log(values);
};
<TextInput
style={styles.inputField}
defaultValue={values.sqmtr}
onChangeText={(text) =>
handleTextChange(text, "sqmtr")}
placeholder="0"
keyboardType={"numeric"}
/>