React: handling an input caret position
3 min readDec 13, 2020
When we modify the text of an HTML input while the user types using React, we may see the caret jumping at the end of the text.
This happens typically when we modify the length of the text the user is typing.
In the example below, a React component is stripping away the ‘&’ illegal characters from the string ‘asd&fasfe’: