How to create an INSTANCE_SWAP prop on a component?

Hi,

I am trying to add an INSTANCE_SWAP property to a component and I’ve tried with both InstanceNode and ComponentSetNode and I get the same error, listed below.

I am passing the ID of the an InstanceNode that I appended to a frame inside the component to which I attach the property.

What kind of node does it need to be?
Can/must the node be a child of the component?

InstanceNode

Many thanks!

I figured it out. The INSTANCE_SWAP property required the id of a ComponentNode or a ComponentSetNode of the instance you are attaching it to:

const newComponent = figma.createComponent();
const instance = componentSetNode.defaultVariant.createInstance();

newComponent.appendChild(instance);
instance.componentPropertyReferences = {
  mainComponent: newComponent.addComponentProperty(
    "PropertyName",
    "INSTANCE_SWAP",
    componentSetNode.defaultVariant.id
  ),
};

// if you start from an instance and do not have access to its original ComponentNode:
newComponent.appendChild(instance);
instance.componentPropertyReferences = {
  mainComponent: newComponent.addComponentProperty(
    "PropertyName",
    "INSTANCE_SWAP",
    instance.mainComponent.id
  ),
};
1 Like