Skip to main content
Question

Can not listen for event in widget


NichtHier

Hi there,

 

does somebody know how to listen to events in widgets?

of course I saw: https://forum.figma.com/topic/show?tid=35307&fid=21

but this code does not work for me:

```ts

const { widget } = figma;

const { Text, useEffect, waitForTask } = widget;

 

function EventHandlerExample() {

useEffect(() => {

const logSelection = () => {

console.log('NEVER');

console.log(figma.currentPage.selection);

};

 

console.log( figma.currentPage);

 

figma.currentPage.on("nodechange", logSelection);

return () => figma.currentPage.off("nodechange", logSelection);

});

 

useEffect(() => {

waitForTask(

new Promise((resolve) => {

setTimeout(() => {

resolve(true);

}, 60000); // Some arbitrary long time

})

);

});

 

return <Text>Event handler example</Text>;

}

 

widget.register(EventHandlerExample);

```

Tell me why, please!

0 replies

Be the first to reply!

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