How to assign per-tab data?

I want to set and get data from each tab.
like

const tab = await browser.tabs.getCurrent();
tab.mydata += 1;

Currently, I implements things like that using tabId and I have to manage them manullay, releasing when the tab is closed.
I wonder if there’s any convenient way to do it.

Storing the extra data by tab ID would be the common pattern, however recently a new API has been introduced to make it much simpler: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/sessions/setTabValue