# Tutorial - create a sidebar plugin and persist the data in a config node

**URL:** <https://discourse.nodered.org/t/tutorial-create-a-sidebar-plugin-and-persist-the-data-in-a-config-node/82020>\
**Category:** Developing Nodes\
**Created:** [14 October 2023 07:24 UTC](https://discourse.nodered.org/t/tutorial-create-a-sidebar-plugin-and-persist-the-data-in-a-config-node/82020 "2023-10-14T07:24:22Z")\
**Posts on this page:** 1\
**Showing post:** 30

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [27 October 2023 16:26 UTC](https://discourse.nodered.org/t/tutorial-create-a-sidebar-plugin-and-persist-the-data-in-a-config-node/82020/30 "2023-10-27T16:26:09Z")

</div>

Note that I have updated my original code above, based on some feedback from @gregorius 👍

The original sidebar was initialized every time the 'Deploy' button was clicked. Because the wrong 'runtime-state' event handler was removed, e.g. the handler of another sidebar.

The code is now refactored to something like this, to make sure our sidebar event handler function is only called once (i.e. when all the nodes have been loaded):

```auto
var initializeSidebar = function( ) { 
   // Remove the event handler, to avoid that the sidebar is initialized at every deploy
   RED.events.off('runtime-state', initializeSidebar); 
    ...
}

// Add your plugin as a new tabsheet in the right sidebar AFTER the flow editor is completely started
RED.events.on('runtime-state', initializeSidebar);

```

---

_[View the full topic](https://discourse.nodered.org/t/tutorial-create-a-sidebar-plugin-and-persist-the-data-in-a-config-node/82020)._
