Skip to main content

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!

Be the first to reply!