I'm trying to create a multi-line array of inputs within which I could edit the code using draft-js. How can I change the code below to access and write data to an array element?
import React, { useState } from 'react';
import { EditorState } from 'draft-js';
import { Editor } from 'react-draft-wysiwyg';
import { convertToHTML } from 'draft-convert';
import DOMPurify from 'dompurify';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
import './App.css';
const App = () => {
const [editorState, setEditorState] = useState(
() => EditorState.createEmpty(),
);
const [convertedContent, setConvertedContent] = useState('');
const handleEditorChange = (state: React.SetStateAction<EditorState>) => {
setEditorState(state);
convertContentToHTML();
}
const convertContentToHTML = () => {
let currentContentAsHTML = convertToHTML(editorState.getCurrentContent());
setConvertedContent(currentContentAsHTML);
}
const createMarkup = (html: string | Node) => {
return {
__html: DOMPurify.sanitize(html)
}
}
console.log(convertedContent);
return (
<div className="App">
<header className="App-header">
Rich Text Editor Example
</header>
<Editor
editorState={editorState}
onEditorStateChange={handleEditorChange}
wrapperClassName="wrapper-class"
editorClassName="editor-class"
toolbarClassName="toolbar-class"
/>
<div className="preview" dangerouslySetInnerHTML={createMarkup(convertedContent)}></div>
</div>
)
}
export default App;
The attached code implements the draft-js structure itself with a text control panel, as well as translating value into html and then displaying it in textarea