Skip to main content
Solved

How to get a node reference from a widget?

  • July 27, 2023
  • 1 reply
  • 337 views

function update(node, count) {
    // set some property on node using count
}

function Widget() {
  const [count, setCount] = useSyncedState('count', 0)

  return (
    <Frame width={100} height={100} >
      <Text
       onClick={
         () => {
            // update(??, count)
            setCount(count + 1)
         }
       }
       >
       The count is: {count}
      </Text>
    </Frame>
  )
}

How do I send the text node’s id or WidgetNode’s reference to the update function?

I think we can get the WidgetNode’s reference from figma.currentPage.selection[0], right? Is there any way to get a TextNode’s reference if the widget has multiple TextNodes?

Best answer by tank666

You can get a WidgetNode, but not its nested nodes.

figma.com
View original
This topic has been closed for replies.

1 reply

tank666
  • 4873 replies
  • Answer
  • July 27, 2023

You can get a WidgetNode, but not its nested nodes.

figma.com

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