jodit / jodit-react

React wrapper for Jodit
MIT License
363 stars 120 forks source link

Editor loose focus || Storing content is not working #233

Open ajayahara opened 1 year ago

ajayahara commented 1 year ago

Look the below example for solution:-

import { useState, useRef, useMemo} from 'react';
import JoditEditor from 'jodit-react';
const JoditEditorJsx = ({placeholder}) => {
    const editor = useRef(null);
    const [content, setContent] = useState('');

    const config = useMemo(()=>{
        return {
            readonly: false,
            placeholder: placeholder||'Start typings...',
            height:'500px',
            theme:'dark'
        }
    },[placeholder])

    return (
       <>
        <JoditEditor
            ref={editor}
            value={content}
            config={config}
            tabIndex={1}
            onBlur={newContent => setContent(newContent)}
            onChange={(newContent) =>{setContent(newContent)}}
        />
        <div>
            <h2>Result from JoditEditor</h2>
            <div>
                {
                    content
                }
            </div>
        </div>
       </>
    );
}

export default JoditEditorJsx
alyvofficial commented 1 month ago

Thank u!