Where is the best place to put addNotificationListener in a React component?

I’m taking a look at the event listener code in the documentation:

var listener = (e,d) => { console.log(e,d); }
require('photoshop').action.addNotificationListener([
    {
        event: "select"
    },
    {
        event: "open"
    } // any other events...
], listener);

And I am just curious if there is a best practice on where to place it in a React component.
thanks!

I suppose it depends what are you going to listen to. Just there shouldn’t be multiple listeners for the same event.

I personally have it right after entrypoints.setup(), but I assume you could have it anywhere, especially if you add and remove listeners on the go.

1 Like