On OnChange the editor loses focus
See original GitHub issueHi, I need to use setContent on the event OnChange instead of on OnBlur but if I do this the editor loses the focus every time the function is called and some errors appear on the console. Does anyone know how to solve this? Or is it mandatory to use onBlur? Thanks!
import React, { useState, useRef } from "react";
import JoditEditor from "jodit-react";
const Editor = ({ value, onChange }: IEditorProps): JSX.Element => {
const editor = useRef(null);
const [content, setContent] = useState(value);
const config = {
readonly: false,
};
const handleChange = (newContent: string) => {
setContent(newContent);
};
return (
<JoditEditor ref={editor} value={content} config={config} onChange={handleChange} />
);
};
interface IEditorProps {
value: string;
onChange: (value: string) => void;
}
export default Editor;

Issue Analytics
- State:
- Created 4 years ago
- Reactions:17
- Comments:48
Top Results From Across the Web
Jodit react editor loses focus on onchange method
In react-jodit plugin, when we use onchange event, it loses focus from input after typing one character.
Read more >React Text Input Losing Focus After Each Keypress
This bug took me a while to figure out, so I thought I would share the cause and the fix. I had a...
Read more >Focusing: focus/blur - The Modern JavaScript Tutorial
The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an...
Read more >DropDown or ComboBox loses focus on change when used ...
DropDown or ComboBox loses focus on change when used as a custom editor with reference data for inline Grid editing.
Read more >React.js loses input focus on typing
Then react re-rendered the page and updated the input. But because the key was different between re-renders it throws away the old input...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem is onChange always re-render the state. So when re-render the focus will be lost. I have a solution to avoid this problem. Use
useMemo
hooks to solve this.For some reason memoizing config helped me