marktext / muya

📄 Future markdown editor for web browser applications development
MIT License
615 stars 54 forks source link

Functions are undefined #145

Closed neopostmodern closed 6 months ago

neopostmodern commented 8 months ago

Describe the bug All of the functions on an instantiated Muya are undefined. Below is just one example, I inspected the object and all functions are undefined.

To Reproduce

import Muya from '@marktext/muya';
import { useEffect, useRef } from 'react';

const RichMarkdownEditor = ({
  markdown,
  onBlur,
}: {
  markdown: string;
  onBlur: (value: string) => void;
}) => {
  const muyaContainer = useRef<HTMLDivElement | null>(null);

  useEffect(() => {
    if (!muyaContainer.current) {
      return;
    }

    const muya = new Muya(muyaContainer.current);
    muya.setContent(markdown);
  }, [muyaContainer]);

  return <div ref={muyaContainer}>Muya editor loading...</div>;
};

export default RichMarkdownEditor;

Upon execution you immediately get "TypeError: muya.setContent is not a function"

Expected behavior Use the functions.

Actual behavior Error is thrown.

Operation System and Browser version (please complete the following information):

Muya Version 0.2.5

Jocs commented 7 months ago
const options: any = {
      disableHtml: true,
};

if (jsonState.length) {
    options.json = jsonState;
} else {
    options.markdown = markdown;
}
const muya = new Muya(editorRef.current, options);

muya.init();

you can put your markdown in the options, and call muya.init

There is an example in the example folder.

yfwz100 commented 6 months ago

Why not call init inside constructor instead of calling init() explicitly?