diff --git a/CHANGELOG.md b/CHANGELOG.md index ed42f7f7..1555e19e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -537,3 +537,8 @@ online - useResizeObserver hook & documentation +## [0.27.1] - 2020-07-08 + +### Fixed + +- useStorage throws an error on server side rendering as the window object is not defined yet diff --git a/package.json b/package.json index 52bef637..1aca43ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "beautiful-react-hooks", - "version": "0.27.0", + "version": "0.27.1", "description": "A collection of beautiful (and hopefully useful) React hooks to speed-up your components and hooks development", "main": "dist/index.js", "module": "dist/esm/index.js", diff --git a/src/useStorage.js b/src/useStorage.js index 5dbd5158..a195282b 100644 --- a/src/useStorage.js +++ b/src/useStorage.js @@ -9,7 +9,6 @@ import isDevelopment from './utils/isDevelopment'; */ const useStorage = (type) => { const storageName = `${type}Storage`; - const storage = window[storageName]; if (isClient && !isAPISupported(storageName)) { // eslint-disable-next-line no-console @@ -28,6 +27,7 @@ const useStorage = (type) => { return [JSON.stringify(defaultValue), () => undefined]; } + const storage = window[storageName]; const [value, setValue] = useState( safelyParseJson(storage.getItem(storageKey) || JSON.stringify(defaultValue)), );