diff --git a/CHANGELOG.md b/CHANGELOG.md index f44c238..d569bc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # react-viewport-hooks Changelog +## 1.5.0 (2020-06-01) + +#### Bug Fix + +- fixed incorrect options merging +- fixed default value type + ## 1.4.0 (2020-05-25) #### Breaking Changes diff --git a/package.json b/package.json index 2bc1359..4633916 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-viewport-hooks", - "version": "1.4.0", + "version": "1.5.0", "description": "Get real viewport width & height", "author": "Jakub Biesiada", "license": "MIT", @@ -36,22 +36,22 @@ "@testing-library/react-hooks": "^3.2.1", "@types/jest": "^25.2.3", "@types/react": "^16.9.35", - "@typescript-eslint/parser": "^3.0.0", + "@typescript-eslint/parser": "^3.1.0", "eslint": "^7.1.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-prettier": "^3.1.3", "eslint-plugin-react": "^7.20.0", - "eslint-plugin-react-hooks": "^4.0.2", + "eslint-plugin-react-hooks": "^4.0.4", "husky": "^4.2.5", "jest": "^26.0.1", - "lint-staged": "^10.2.6", + "lint-staged": "^10.2.7", "prettier": "^2.0.5", "react": "^16.13.1", "react-dom": "^16.13.1", "react-test-renderer": "^16.13.1", "rollup-plugin-terser": "^6.1.0", "rollup-plugin-typescript2": "^0.27.1", - "ts-jest": "^26.0.0", + "ts-jest": "^26.1.0", "typescript": "^3.9.3" }, "peerDependencies": { diff --git a/src/defaults.ts b/src/defaults.ts index 94f436c..998a325 100644 --- a/src/defaults.ts +++ b/src/defaults.ts @@ -1,5 +1,5 @@ export const defaultOptions = { - updateOnResize: true, - defaultVW: undefined, defaultVH: undefined, + defaultVW: undefined, + updateOnResize: true, }; diff --git a/src/interfaces/options.ts b/src/interfaces/options.ts index 9ae6edd..f17a33e 100644 --- a/src/interfaces/options.ts +++ b/src/interfaces/options.ts @@ -1,5 +1,5 @@ export interface Options { - readonly updateOnResize?: boolean; readonly defaultVW?: number; readonly defaultVH?: number; + readonly updateOnResize?: boolean; } diff --git a/src/useViewport.ts b/src/useViewport.ts index e0979d3..acdf6bc 100644 --- a/src/useViewport.ts +++ b/src/useViewport.ts @@ -4,11 +4,14 @@ import { defaultOptions } from './defaults'; import { Options } from './interfaces/options'; -export const useViewport = (options: Options = defaultOptions) => { - const { updateOnResize, defaultVW, defaultVH } = options; - - const [vw, setVW] = useState(defaultVW); - const [vh, setVH] = useState(defaultVH); +export const useViewport = (options?: Options) => { + const { updateOnResize, defaultVW, defaultVH } = { + ...defaultOptions, + ...options, + }; + + const [vw, setVW] = useState(defaultVW as number); + const [vh, setVH] = useState(defaultVH as number); useEffect(() => { const setSizes = () => { diff --git a/yarn.lock b/yarn.lock index c7c176f..b5e3325 100644 --- a/yarn.lock +++ b/yarn.lock @@ -758,30 +758,30 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/experimental-utils@3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.0.tgz#1ddf53eeb61ac8eaa9a77072722790ac4f641c03" - integrity sha512-BN0vmr9N79M9s2ctITtChRuP1+Dls0x/wlg0RXW1yQ7WJKPurg6X3Xirv61J2sjPif4F8SLsFMs5Nzte0WYoTQ== +"@typescript-eslint/experimental-utils@3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.1.0.tgz#2d5dba7c2ac2a3da3bfa3f461ff64de38587a872" + integrity sha512-Zf8JVC2K1svqPIk1CB/ehCiWPaERJBBokbMfNTNRczCbQSlQXaXtO/7OfYz9wZaecNvdSvVADt6/XQuIxhC79w== dependencies: "@types/json-schema" "^7.0.3" - "@typescript-eslint/typescript-estree" "3.0.0" + "@typescript-eslint/typescript-estree" "3.1.0" eslint-scope "^5.0.0" eslint-utils "^2.0.0" -"@typescript-eslint/parser@^3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.0.tgz#fe9fdf18a1155c02c04220c14506a320cb6c6944" - integrity sha512-8RRCA9KLxoFNO0mQlrLZA0reGPd/MsobxZS/yPFj+0/XgMdS8+mO8mF3BDj2ZYQj03rkayhSJtF1HAohQ3iylw== +"@typescript-eslint/parser@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.1.0.tgz#9c02ba5d88ad2355672f39e6cd4176f172dd47f8" + integrity sha512-NcDSJK8qTA2tPfyGiPes9HtVKLbksmuYjlgGAUs7Ld2K0swdWibnCq9IJx9kJN8JJdgUJSorFiGaPHBgH81F/Q== dependencies: "@types/eslint-visitor-keys" "^1.0.0" - "@typescript-eslint/experimental-utils" "3.0.0" - "@typescript-eslint/typescript-estree" "3.0.0" + "@typescript-eslint/experimental-utils" "3.1.0" + "@typescript-eslint/typescript-estree" "3.1.0" eslint-visitor-keys "^1.1.0" -"@typescript-eslint/typescript-estree@3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.0.tgz#fa40e1b76ccff880130be054d9c398e96004bf42" - integrity sha512-nevQvHyNghsfLrrByzVIH4ZG3NROgJ8LZlfh3ddwPPH4CH7W4GAiSx5qu+xHuX5pWsq6q/eqMc1io840ZhAnUg== +"@typescript-eslint/typescript-estree@3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.1.0.tgz#eaff52d31e615e05b894f8b9d2c3d8af152a5dd2" + integrity sha512-+4nfYauqeQvK55PgFrmBWFVYb6IskLyOosYEmhH3mSVhfBp9AIJnjExdgDmKWoOBHRcPM8Ihfm2BFpZf0euUZQ== dependencies: debug "^4.1.1" eslint-visitor-keys "^1.1.0" @@ -1667,10 +1667,10 @@ eslint-plugin-prettier@^3.1.3: dependencies: prettier-linter-helpers "^1.0.0" -eslint-plugin-react-hooks@^4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.0.2.tgz#03700ca761eacc1b6436074c456f90a8e331ff28" - integrity sha512-kAMRjNztrLW1rK+81X1NwMB2LqG+nc7Q8AibnG8/VyWhQK8SP6JotCFG+HL4u1EjziplxVz4jARdR8gGk8pLDA== +eslint-plugin-react-hooks@^4.0.4: + version "4.0.4" + resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.0.4.tgz#aed33b4254a41b045818cacb047b81e6df27fa58" + integrity sha512-equAdEIsUETLFNCmmCkiCGq6rkSK5MoJhXFPFYeUebcjKgBmWWcgVOqZyQC8Bv1BwVCnTq9tBxgJFgAJTWoJtA== eslint-plugin-react@^7.20.0: version "7.20.0" @@ -3168,10 +3168,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= -lint-staged@^10.2.6: - version "10.2.6" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-10.2.6.tgz#7d9658bd89dee946a859cbfc6e09566a9fb50b53" - integrity sha512-2oEBWyPZHkdyjKcIv2U6ay80Q52ZMlZZrUnfsV0WTVcgzPlt3o2t5UFy2v8ETUTsIDZ0xSJVnffWCgD3LF6xTQ== +lint-staged@^10.2.7: + version "10.2.7" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-10.2.7.tgz#6e47860af3d86a6a01849cbf8ba80f7754aae6eb" + integrity sha512-srod2bTpF8riaLz+Bgr6v0mI/nSntE8M9jbh4WwAhoosx0G7RKEUIG7mI5Nu5SMbTF9o8GROPgK0Lhf5cDnUUw== dependencies: chalk "^4.0.0" cli-truncate "2.1.0" @@ -4673,10 +4673,10 @@ tr46@^2.0.2: dependencies: punycode "^2.1.1" -ts-jest@^26.0.0: - version "26.0.0" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.0.0.tgz#957b802978249aaf74180b9dcb17b4fd787ad6f3" - integrity sha512-eBpWH65mGgzobuw7UZy+uPP9lwu+tPp60o324ASRX4Ijg8UC5dl2zcge4kkmqr2Zeuk9FwIjvCTOPuNMEyGWWw== +ts-jest@^26.1.0: + version "26.1.0" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.1.0.tgz#e9070fc97b3ea5557a48b67c631c74eb35e15417" + integrity sha512-JbhQdyDMYN5nfKXaAwCIyaWLGwevcT2/dbqRPsQeh6NZPUuXjZQZEfeLb75tz0ubCIgEELNm6xAzTe5NXs5Y4Q== dependencies: bs-logger "0.x" buffer-from "1.x"