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

Quick start can't see anything and errors #14

Closed
yuriten opened this issue Aug 15, 2022 · 2 comments
Closed

Quick start can't see anything and errors #14

yuriten opened this issue Aug 15, 2022 · 2 comments

Comments

@yuriten
Copy link

yuriten commented Aug 15, 2022

In a cra project, write the following code, there are two error points inside, and even if these two points are solved, nothing can be rendered in the web page window.

// EditorTester.jsx

import React, { useEffect } from 'react'
import VEditor from '@vesoft-inc/veditor'

export const EditorTester = () => {
  let editorRef = React.useRef()

  useEffect(() => {
    const editor = new VEditor(editorRef.current)
    let index = 0
    console.log('editor', editor)
    const add = () => {
      // 如果改为 graph?. 则会报错 Uncaught TypeError: Cannot read properties of undefined (reading 'node')
      editor.graph.node.addNode({
        uuid: index,
        type: 'default', // node shape type
        name: 'test' + index++,
        x: window.innerWidth * Math.random(),
        y: 300 * Math.random(),
      })
    }
    for (let x = 0; x < 50; x++) {
      add()
    }
    // add line
    for (let x = 0; x < 10; x++) {
      editor.graph?.line.addLine({
        from: Math.floor(50 * Math.random()),
        to: Math.floor(50 * Math.random()),
        fromPoint: 1,
        toPoint: 0,
      })
    }

    // 这行会报错 Uncaught TypeError: Cannot read properties of undefined (reading 'getData')
    console.log(editor.schema.getData())
  }, [])

  return <div ref={editorRef} id='ca'></div>
}

the edior log:

CleanShot 2022-08-16 at 01 47 21

So...What do I need to do to see a basic editor in React project?

@yuriten
Copy link
Author

yuriten commented Aug 15, 2022

"如果改为 graph?. 则会报错 "这一句写反了,应该是“ 如果不改为 graph?. 则会报错 ”

@mizy
Copy link
Contributor

mizy commented Aug 16, 2022

"如果改为 graph?. 则会报错 "这一句写反了,应该是“ 如果不改为 graph?. 则会报错 ”

new VEditor({ dom: this.editorRef, showMiniMap: true });
see demo/index.js
I will write a api doc this week .

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

2 participants