Skip to content

Commit 9209ad3

Browse files
authored
Merge pull request #1870 from gregnb/fixbug/window_not_defined
fix : Changed to work only in browser(storageKey)
2 parents 57e18e0 + ee56bf7 commit 9209ad3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ The component accepts the following props:
247247
|**`tableBodyMaxHeight`**|string||CSS string for the height of the table (ex: '500px', '100%', 'auto').
248248
|**`textLabels`**|object||User provided labels to localize text.
249249
|**`viewColumns`**|boolean or string|true|Show/hide viewColumns icon from toolbar. Possible values:<p><ul><li>true: Button is visiable and clickable.</li><li>false: Button is not visible.</li><li>disabled: Button is visible, but not clickable.</li></ul></p>
250-
|**`storageKey`**|string|| save current state to local storage.
250+
|**`storageKey`**|string|| save current state to local storage(Only browser).
251251

252252
## Customize Columns
253253

src/localStorage/load.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
export const load = storageKey => JSON.parse(window.localStorage.getItem(storageKey));
1+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
2+
3+
export const load = storageKey => {
4+
if (isBrowser) {
5+
return JSON.parse(window.localStorage.getItem(storageKey));
6+
} else if (storageKey !== undefined) {
7+
console.warn('storageKey support only on browser');
8+
return undefined;
9+
}
10+
};

0 commit comments

Comments
 (0)