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

Support rendering into target node #407

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

luke-john
Copy link

Hey, thanks for this great library.

I noticed that, while the render function is documented to support rendering to a target container, it actually only supports rendering to the "root".

I wanted to be able to render different things to different locations based on some user interactions, which is not possible with this limitation.

I've managed to support my use case with a small tweak.

Something to note, if the render is passed a Page element and a non root node id, the page will be created with all it's children, but react-figma will throw because you can't move a page to node which isn't root.

@ilyalesik
Copy link
Member

Hey! I agree that the problem takes place. But render(<App />, figma.currentPage.id); runs in the UI thread, so it'll produce Uncaught ReferenceError: figma is not defined

@luke-john
Copy link
Author

luke-john commented Apr 6, 2021

Ahh yes.

In my usage, I'm using another tool similar to figma-jsonrpc, which allows me to retrieve that on the main.

But it's non trivial to set that up, as figma-jsonrpc uses onmessage, so any other comms have to use on('message', plus do all the setup to get IDs from the UI.

Would you be open to the feature if I redid the docs to make it clear users need to implement retrieval of a figma node ID themselves?

@luke-john
Copy link
Author

luke-john commented Apr 6, 2021

Another thing to mention.

Running it from the UI like this could trip the user up, as the reconciler will stay running. And if the user tries and run multiple renders on the same nodes, you'll have competing reconcilers/reconciliation.

I've made an additional change to the render function to have it return a function that "shuts down" the reconciler.

I understand if these changes are out of scope of your project.

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

Successfully merging this pull request may close these issues.

None yet

2 participants