Skip to main content
Question

How to have a widget duplicate itself after a user interaction?

  • September 28, 2022
  • 2 replies
  • 419 views

Marijn_Huizendveld

Hi there,

Over the past few days I’ve been playing with APIs to build a FigJam plugin and a FigJam widget that interact to provide the behavior I seek.

What I’d like to do is to make a Widget that creates itself after clicking on a button within the widget itself (similar to the interaction on a sticky note in FigJam).
It seems I need to make a call to figma.importComponentByKeyAsync but for that to work I need to publish my widget first. Is there a way around this?
Or am I taking a completely wrong approach here?

Any help is much appreciated, thanks in advance 😀

All the best, Marijn

2 replies

tank666
  • 4856 replies
  • September 28, 2022

Get the widget id with the useWidgetId() hook, then clone the node with that id.
Check out the code example here:

figma.com

Marijn_Huizendveld

Thanks a lot @tank666! That does the trick 🙂


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