-
-
Notifications
You must be signed in to change notification settings - Fork 744
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
Uncaught Error: Invariant failed: You can only use useNode in the context of <Editor />. #658
Comments
|
When I log the editor I get |
Seems like the error is coming from your |
Thanks for taking the time to reply! Yes, I put the Editor component at the root of the tree:
As i mentioned above, the Editor property inContext returns true when suing useEditor. I just can't use useNode for some reason. If anyone else in the future is having this issue, I fixed it by writing a custom hook (useNodeProps()):
|
Having the same problem. Using useNode outside Frame and inside Editor gives the same error. |
This shouldn't happen and I can't reproduce this so far - I've created a sandbox here with Related components: https://stackblitz.com/edit/stackblitz-starters-hddnpk?file=components%2FText.tsx You can only use |
@prevwong this is how I wanted to structure my app. And as you can see, this returns an error: Do I have always to put the related component inside the corresponding node component file ? |
If you add inside the Frame there is no error. I think it makes sense to have useNode scoped within the Frame element, don't you think? |
Yes, the Otherwise, you can always just get the Node id of the selected node, and then just show the Text settings component if the selected component is a Text node: const MySettingsPanel = () => {
const { selectedType, selectedNodeId } = useEditor(state => {
return {
selectedType: [...state.events.selected][0]?.data.type
selectedNodeId: [...state.events.selected][0]?.id,
}
});
if ( selectedType === 'Text' ) {
return <TextSettings nodeId={selectedNodeId} />
}
} |
Ah I see. thanks for your help! |
Describe the bug
I've wrapped my entire app in an Editor component and I'm still getting this error when using useNode() in a "related" settings component. It works fine when using it in a UserComponent, but everytime i want to useNode inside a related settings component i get an error.
ComponentPreferences.tsx in another directory:
Uncaught Error: Invariant failed: You can only use useNode in the context of
<Editor />
.Please only use useNode in components that are children of the
<Editor />
component.at invariant (tiny-invariant.js:12)
at ye (index.js:1)
at me (index.js:1)
at ComponentPreferences (ComponentPreferences.tsx:11)
at renderWithHooks (react-dom.development.js:16305)
at mountIndeterminateComponent (react-dom.development.js:20074)
at beginWork (react-dom.development.js:21587)
at beginWork$1 (react-dom.development.js:27426)
at performUnitOfWork (react-dom.development.js:26557)
at workLoopSync (react-dom.development.js:26466)
invariant @ tiny-invariant.js:12
ye @ index.js:1
me @ index.js:1
ComponentPreferences @ ComponentPreferences.tsx:11
renderWithHooks @ react-dom.development.js:16305
mountIndeterminateComponent @ react-dom.development.js:20074
beginWork @ react-dom.development.js:21587
beginWork$1 @ react-dom.development.js:27426
performUnitOfWork @ react-dom.development.js:26557
workLoopSync @ react-dom.development.js:26466
renderRootSync @ react-dom.development.js:26434
recoverFromConcurrentError @ react-dom.development.js:25850
performConcurrentWorkOnRoot @ react-dom.development.js:25750
workLoop @ scheduler.development.js:266
flushWork @ scheduler.development.js:239
performWorkUntilDeadline @ scheduler.development.js:533
The text was updated successfully, but these errors were encountered: