medium-editor icon indicating copy to clipboard operation
medium-editor copied to clipboard

Usage with React?

Open teb111 opened this issue 2 years ago • 2 comments

Please there is nowhere in the documentation that explains usage with react.js

teb111 avatar Jan 27 '22 10:01 teb111

https://github.com/wangzuo/react-medium-editor

yojona avatar Feb 02 '22 01:02 yojona

You can try this maybe:

import * as React from "react";
import MediumEditor from "medium-editor";
import "medium-editor/dist/css/medium-editor.css";
import "medium-editor/dist/css/themes/default.css";
import classNames from "classnames";

const Article: React.FC = () => {
  const [editor, setEditor] = React.useState<any>();

  const onRefChange = React.useCallback((node) => {
    if (node === null) {
        setEditor(null)
    } else {
      if (editor == null) {
        const et = new MediumEditor(node);
        setEditor(et);
      }
    }
  }, []); // adjust deps

  return (
    <div className="w-full bg-[#21212B] text-white h-[500px] overflow-y-scroll px-4 py-3">
      <div
        className={classNames(
          "w-full h-full prose text-white",
          "prose-headings:text-white ",
          "prose-a:text-[#94C7E9]",
          "focus:outline-none"
        )}
        ref={onRefChange}
      ></div>
    </div>
  );
};
export default Article;

i-am-mani avatar Feb 04 '22 04:02 i-am-mani