@steroidsjs/core 3.0.11 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/hooks/useTree.js +12 -5
  2. package/package.json +1 -1
package/hooks/useTree.js CHANGED
@@ -124,7 +124,10 @@ function useTree(config) {
124
124
  var selectedItem = findChildById(items, selectedItemId, primaryKey);
125
125
  setSelectedUniqueId(selectedItem ? selectedItem.uniqueId : null);
126
126
  }, [items]);
127
- var localTree = JSON.parse(clientStorage.get(CLIENT_STORAGE_KEY)) || {};
127
+ var localTree = (0, react_1.useMemo)(function () {
128
+ var rawLocalTree = clientStorage.get(CLIENT_STORAGE_KEY);
129
+ return rawLocalTree ? JSON.parse(rawLocalTree) : {};
130
+ }, [clientStorage]);
128
131
  var saveInClientStorage = function () {
129
132
  if (config.saveInClientStorage) {
130
133
  localTree[config.clientStorageId] = expandedItems;
@@ -142,10 +145,14 @@ function useTree(config) {
142
145
  (0, react_use_1.useUnmount)(function () {
143
146
  saveInClientStorage();
144
147
  });
145
- (0, react_use_1.useBeforeUnload)(function () {
146
- saveInClientStorage();
147
- return true;
148
- });
148
+ (0, react_1.useEffect)(function () {
149
+ if (config.saveInClientStorage) {
150
+ window.addEventListener('beforeunload', saveInClientStorage);
151
+ }
152
+ return function () {
153
+ window.removeEventListener('beforeunload', saveInClientStorage);
154
+ };
155
+ }, [config.saveInClientStorage, saveInClientStorage]);
149
156
  var onExpand = (0, react_1.useCallback)(function (e, uniqueId, item) {
150
157
  var _a;
151
158
  e.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {