I wrote plugin with UI for Figma using figma-api and TypeScript. Project consist of two main files:
code.ts
for calling figma-api
ui.html
with <script>...</script>
with plugin`s user interface.
My plugin is working with data of selection on current page, so I send from code.ts
into ui
data of for example this object:
figma.currentPage.selection[0]
How can I add event listener to figma.currentPage
? For example, if user selected some other element on figma board, figma.currentPage.selection
will change and I want to sent new data into ui
.
Have you any ideas?
I think this is the answer.
figma.on('selectionchange', () => {
console.log(figma.currentPage.selection);
});