'Cursor is going at the start automatically in contentEditable

I am creating a website builder. For Text edit, I m using contentEditable and to capture its state I m using the onInput event. but I don't know why every time I type something cursor goes to start.

CodeSandBox



Solution 1:[1]

you CHANGE the state for each click and you display it. Cursor is reset when state is updated replace onInput with onBlur

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Юрий Копоть