Listening for changes using figma.on()

I want to change my plugin UI when the selection changes in the editor.

This is the code I am using to listen for changes in my code.ts file:

figma.on("selectionchange", () => {

And this is the code I’m using to receive the changes in ui.html:

onmessage = (event) => {
    document.getElementById('layers-selected').innerHTML = `${} text layer${ === 1 ? '':'s'} selected`

However, this isn’t working. Am I using a wrong approach? If so, what would be the right one?

The code snippets shown work as expected. Check the code you didn’t share.


Thanks. The bug was that I was sending the variable v=value, which was declared when the plugin first ran.

Instead, I should be sending real time ‘value’, and not the previously defined variable.