I have the following code:
const components = findComponentsInPage(componentPage);
const selectedComponent = components.filter((component) => {
return component.name === nameComponent;
})[0];
try {
console.log('Creating component instance...');
const componentInstance = selectedComponent.instance.createInstance();
selectedComponent has the following interface:
interface IComponent {
name: string;
instance: ComponentNode;
}
So as you can see, I’m passing the ComponentNode to createInstance() function. However, I get the following error:
Any ideas? I’m recovering the ComponentNode from the page.children by their name.
I identified a possible reason:
Previously i was getting the ComponentNode with a different approach and I was getting this console.log
But now I’m getting
Now I have a component with less fields, but I don’t know why. I’m getting it from the page, any ideas why a component would have less fields using one approach or another? It’s incomplete now so I guess that’s why it doesn’t have the createInstance function.
For more context, I’m trying to create Instances of components that I have in another document, published in a library in a different Figma file. But apparently I can’t do it using Rest API, it doesn’t return the entire information as Plugin API does. What would be the best approach to achieve this then? I’m creating a plugin that reads the components in a page and creates instances of them in another file.
Changed my approach and now I’m recovering component keys through REST API and using Figma.importComponentByKeyAsync() in order to get the component.
Looks like it’s working.