I am trying to implement Input Mask with children as input component, I used https://github.com/sanniassin/react-input-mask. The problem is while onChange() event triggers setState() is called and the state is updated. While updating the state the component is re-rendered. So the state value is also updated and cursor moved to the end of the input value.I am expecting it should stayed on changing position. Here is my code
import InputMask from 'react-input-mask';
const [state, setState] = useState<StateTypes>({
myVal: '123.123.123-56'
});
const onChangeValue = (inputVal: any) => {
setState({
myVal: inputVal
});
};
<InputMask mask="999.999.999-99" onChange={onChangeValue} value={state.myVal}>
<Input name={'myVal'} />
</InputMask>
After setting the state input component is re-rendered, so cursor point moved to the end. Can someone help me out.
Thanks