1

I'm trying to make a markdown editor with React. I am using react-markdown library.

I wrote the same as the document, but the conversion does not work. When I check the element in devtools, the tag is changed normally.

What could be the problem?

// App.tsx

function App() {
  const [inputText, setInputText] = useState<string>('');

  const handleInputText = (e: ChangeEvent<HTMLTextAreaElement>) => {
    const { value } = e.target;
    setInputText(value);
  };
  return (
    <Container>
      <Header>
        <p>Simple Markdown Editor</p>
      </Header>
      <Wrapper>
        <Editor onTextChange={handleInputText} />
        <Result text={inputText} />
      </Wrapper>
    </Container>
  );
}

export default App;
// Editor.tsx

function Editor({ onTextChange }: { onTextChange: (e: ChangeEvent<HTMLTextAreaElement>) => void }) {
  return (
    <Wrapper>
      <TextareaAutosize autoFocus placeholder="Write here.." onChange={(e) => onTextChange(e)} />
    </Wrapper>
  );
}

export default Editor;
// Result.tsx

function Result({ text }: { text: string }) {
  return (
    <Wrapper>
      <ReactMarkdown remarkPlugins={[remarkGfm]}>{text}</ReactMarkdown> // this code
    </Wrapper>
  );
}

export default Result;

enter image description here

Enjoywater
  • 11
  • 2

0 Answers0