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

How to get a React Component of blocksuite? #6943

Closed
UndefinedVoidNull opened this issue May 1, 2024 · 2 comments
Closed

How to get a React Component of blocksuite? #6943

UndefinedVoidNull opened this issue May 1, 2024 · 2 comments
Labels
type:question Question about framework usage

Comments

@UndefinedVoidNull
Copy link

I noticed blocksuite is based on Web Component implemented by Lit.

And I want to use blocksuite in my React project. That's because Web Component is not working great in React for things like the props, events, and so on. So I tried to use createComponent in @lit/react to create a wrapper for React.

But I got this type of Error/Warning React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined

When I print the wrapped components, they look like this
image

Then I found Affine is using a customized version of @lit/react in packages/frontend/core/src/components/blocksuite/block-suite-editor/lit-adaper.ts (Is this a typo? Should it be lit-adpater?)

Then I tried to export adpated like this

export const adapted = {
  DocEditor: createReactComponentFromLit({
    react: React,
    elementClass: PageEditor,
  }),
  DocTitle: createReactComponentFromLit({
    react: React,
    elementClass: DocTitle,
  }),
  PageMetaTags: createReactComponentFromLit({
    react: React,
    elementClass: DocMetaTags,
  }),
  EdgelessEditor: createReactComponentFromLit({
    react: React,
    elementClass: EdgelessEditor,
  }),
  BiDirectionalLinkPanel: createReactComponentFromLit({
    react: React,
    elementClass: BiDirectionalLinkPanel,
  }),
};

Then import adapted and using adapted.XXX in my React project.
But still encounter the problem like this
image
image
image

Affine is using blocksuite with React just fine, so I just want to know how to use blocksuite with React in my own React project?

@doodlewind
Copy link
Member

Maybe the error could be fixed by assigning an empty doc to the editor instance (like #6522)? We have plan on #6490 for official react component integration, which should be coming soon.

@doodlewind doodlewind added the type:question Question about framework usage label May 1, 2024
@UndefinedVoidNull
Copy link
Author

Maybe the error could be fixed by assigning an empty doc to the editor instance (like #6522)? We have plan on #6490 for official react component integration, which should be coming soon.

Thank you. 😊 Really excited about React integration coming.

Using lit-adaper.ts in Affine and assigning an empty doc would not throwing Errors directly. But still got some weird behaviors.

But use createComponent in @lit/react still throwing an Uncaught TypeError: Cannot read properties of undefined (reading 'slots')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Question about framework usage
Projects
Archived in project
Development

No branches or pull requests

2 participants