I have an input field that needs an onChange event to be bound on mounting the component. The onChange event needs to update the state. However, the state never gets updated because the onChange event always has the initial state. What is the best way to make this work?
Here is my code:
const someComponent: FC<someComponent> = props => {
const [count, setCount] = useState(0);
const someFunction = () => {
console.log(count) // 0
setCount(count+ 1);
console.log(count) // Also 0
}
useEffect(() => {
inputField.onChange = () => {
someFunction();
}
}, [])
}