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

User Component name doesn't change when specified in config #602

Open
pavsidhu opened this issue Jan 18, 2024 · 1 comment
Open

User Component name doesn't change when specified in config #602

pavsidhu opened this issue Jan 18, 2024 · 1 comment

Comments

@pavsidhu
Copy link
Contributor

Describe the bug

User Component name doesn't reflect what is specified in the UserComponentConfig.

To Reproduce

import { Editor, Element, Frame, useNode } from "@craftjs/core";

function MyUserComponent() {
  const { node } = useNode((node) => ({ node }));
  return <h1>{node.data.name}</h1>;
}
MyUserComponent.craft = { name: "CustomName" };

export default function MyEditor() {
  return (
    <Editor resolver={{ MyUserComponent }}>
      <Frame>
        <Element is={MyUserComponent} />
      </Frame>
    </Editor>
  );
}

Expected behavior

The component shows MyUserComponent but I expect CustomName

Your environment

Software Version(s)
craft.js 0.2.3
React 18.2.0
TypeScript 4.0.1
Browser any
npm/Yarn any
Operating System any
@shota-f
Copy link

shota-f commented Jan 23, 2024

I found name, displayName and resolver-key(important).
Document is heare(https://craft.js.org/docs/api/user-component).
It seems like the updates are not keeping up.
However, the type definitions(UserComponent) of code-base does not betray.

This is simple code.

import { Editor, Element, Frame, UserComponent, useNode } from "@craftjs/core"

const MyUserComponent: UserComponent = () => {
  const { node } = useNode((node) => ({ node }))
  return (
    <div>
      <div>Name: {node.data.name}</div>
      <div>DisplayName: {node.data.displayName}</div>
    </div>
  )
}

// Code completion works for both!
MyUserComponent.craft = { name: "RealName", displayName: "DisplayName" }

export default function MyEditor() {
  return (
    <Editor resolver={{ RealName: MyUserComponent }}>
      <Frame>
        <Element is={MyUserComponent} />
      </Frame>
    </Editor>
  )
}

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