Skip to content
Advertisement

Figma Plugin: callback on file updated

I found the callback ‘on’ interesting but limiting https://www.figma.com/plugin-docs/api/properties/figma-on/#docsNav

I there a way to trigger an event once the file has been updated?

Advertisement

Answer

There is no way to do this at the moment. The only type of update you can get is if selection changes or current page changes. Here is an example from the docs:

figma.on("selectionchange", () => { console.log("changed") })

The method commonly used by plugins to watch for changes on nodes is polling: simply creating an interval or timer and checking if one of properties changed from the previously saved state.

let interval = setInterval(checkNodes, 500) // check every 300ms

const node = figma.currentPage.selection[0] // first node in selection
let nodeWidth = node.width // store node properties to watch

function checkNodes() {
  if (nodeWidth !== node.width) {
    // width changed
  }
  nodeWidth = node.width
}
Advertisement