If I write this in a component:
const [value, setValue] = useState("");
....
return <input onChange={(e) => setValue(e.target.value)} value={value} />
Then react somehow knows how to preserve the cursor position. I'm wondering - how does react do this exactly? All react knows is that I'm resetting the value of the input. Is there some sort of algorithm to find the added letter and add the cursor in at the right place?