Skip to main content
Question

Calling importComponentByKeyAsync on local components

  • June 1, 2021
  • 1 reply
  • 1613 views

Cristiano_Rastelli

Not sure if it’s a bug or a “feature” (jokes apart, I mean if it’s an expected behaviour). Let’s imagine that I have an element that is using a certain component from a library (as an instance), and in my plugin I want to swap that component with another one (“ new ”, of which I have an ID). Usually I would do:

const newMainComponentObject = await figma.importComponentByKeyAsync(newMainComponentKey);
oldComponentInstanceNode.swapComponent(newMainComponentObject);

and this works perfectly fine. Now, what happens is that if the “new” component is a “local” component, it doesn’t work, for the simple reason that calling:

figma.importComponentByKeyAsync(localMainComponentKey);

triggers an error. Now, the question is: why the method importComponentByKeyAsync should not work, even if the component is “local”? (and yes, the local component is published as library).

This is the error I see if I try to import the component in the file where the component is defined:

This is the same command run in another file:

What do you think folks? Bug or expected behaviour?

garaujo
  • October 29, 2021

Hi Cristiano, hope you already found an answer. I had an issue like this. On my case, I was trying to reach a Component but since it was inside a COMPONENT_SET I had to point to the set. Hope this can help someone.

Off topic: Nice article about Style Dictionary on Medium, helped me to test it and brought back my will for code development.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings