Hi, there. I finished Markdown preview which is one of the projects of Frontend Libraries. However, I am not passing the last tests that check for default markdown text appearance on DOM load. Can anybody help me out? I thought maybe if I use useEffect hook, I would pass the tests but I did not. Here is the jsx code:
const { render } = ReactDOM;
marked.setOptions({breaks: true});
const { parse } = marked;
const text = `# This is an H1
## This is an H2
[This is a link](https://example.com)
Here is some inline \`code\`
- This is a list item
> This is a blockquote
![Image alt text](https://example.com/image.jpg)
**This text is bold**`;
function Editor() {
const [ editor, setEditor ] = useState("");
const [ markdown, setMarkdown ] = useState(parse(editor));
const changeEditor = (event) => {
const new_value = event.target.value;
setEditor(new_value);
setMarkdown(parse(new_value));
}
useEffect(() => {
setEditor(text);
setMarkdown(text);
},[]);
return (
<><section id="editor-section">
<h2 class="heading">Editor</h2>
<textarea value={editor} id="editor" onChange={changeEditor}></textarea>
</section>
<section id="markdown-section">
<h2 class="heading">Preview</h2>
<div id="preview" dangerouslySetInnerHTML={{__html: markdown }}></div>
</section>
</>
);
}
render(< Editor />, document.querySelector("#root"));