react-email-editor icon indicating copy to clipboard operation
react-email-editor copied to clipboard

I want to initialize more than one editor on same page

Open aditya-dikonia opened this issue 6 years ago • 4 comments

I'm facing the issue when i append the editor second time on page then editor append in first editor div Can any help me out how i can initialize multiple editor without merging with each other Thanks screenshot-localhost 8080-2018-07-06-15-56-00

aditya-dikonia avatar Jul 07 '18 13:07 aditya-dikonia

This not work for me, anyone with same problem? Any solution?

diegocabrito avatar May 11 '20 16:05 diegocabrito

Guys! It is possible, i did it @cabrahost

xantos008 avatar May 16 '21 13:05 xantos008

I have used this on language multi email templates

xantos008 avatar May 16 '21 13:05 xantos008

Sample, hope this will helps

const emailEditorRef = useRef([null]);
const [inviteTemplates, setInviteTemplates] = useState({
    items: [0, 1] // As many items in array as many editors you will get
    // Also you can use setInviteTemplates for dynamic 
})

useEffect(() => {
    emailEditorRef.current = emailEditorRef.current.slice(0, inviteTemplates.items.length);
    console.log('emailEditorRef', emailEditorRef)
}, [inviteTemplates.items]);


const loadEditorEmail = (index) => {
    if(emailEditorRef && emailEditorRef.current && emailEditorRef.current[index] && emailEditorRef.current[index].editor){
        emailEditorRef.current[index].editor.addEventListener('design:updated', (data) => {
            emailEditorRef.current[index].editor.exportHtml((data) => {
                const { design, html } = data;
                //Your code ...
            });
        });
    } else {
        //Your code ...
    }
}

//This goes in your render function
{inviteTemplates.items.map((item, i) => (
    <div key={i}>
        <Editor
            key={i}
            ref={el => emailEditorRef.current[i] = el}
            onLoad={() => loadEditorEmail(i)}
        />
    </div>
))}

xantos008 avatar May 16 '21 13:05 xantos008