I want to use <div onInput={onChange} contentEditable>
to save user input like textarea does.
I've heard that I need to use onInput listener to trigger fn when input change.
The problem is when I update text with React state, It moves the caret to beginning of text constantly
this is my code
import React from "react";
const App = () => {
const [value, setValue] = React.useState("I am edittable");
const onChange = (e) => {
const html = e.target.innerHTML;
setValue(html);
};
return (
<div onInput={onChange} contentEditable>
{value}
</div>
);
};
export default App;
codesandbox https://codesandbox.io/s/react-editable-cell-pwil6?file=/src/App.js:0-310
how could I fix it ?