Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with React? #1588

Open
teb111 opened this issue Jan 27, 2022 · 2 comments
Open

Usage with React? #1588

teb111 opened this issue Jan 27, 2022 · 2 comments

Comments

@teb111
Copy link

teb111 commented Jan 27, 2022

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

@yojona
Copy link

yojona commented Feb 2, 2022

@i-am-mani
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants