@einride/hooks
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -12,14 +12,14 @@ "use strict"; | ||
const [matches, setMatches] = (0, react_1.useState)(getInitialValue(query)); | ||
const onMediaQueryChange = (0, react_1.useCallback)((event) => { | ||
setMatches(event.matches); | ||
}, []); | ||
(0, react_1.useEffect)(() => { | ||
if (typeof window?.matchMedia === "function") { | ||
setMatches(window.matchMedia(query).matches); | ||
window | ||
.matchMedia(query) | ||
.addEventListener("change", (event) => setMatches(event.matches)); | ||
return () => window | ||
.matchMedia(query) | ||
.removeEventListener("change", (event) => setMatches(event.matches)); | ||
const mediaQueryList = window.matchMedia(query); | ||
setMatches(mediaQueryList.matches); | ||
mediaQueryList.addEventListener("change", onMediaQueryChange); | ||
return () => mediaQueryList.removeEventListener("change", onMediaQueryChange); | ||
} | ||
return undefined; | ||
}, [query]); | ||
}, [query, onMediaQueryChange]); | ||
return matches; | ||
@@ -29,4 +29,3 @@ }; | ||
const getInitialValue = (query) => { | ||
if (typeof window !== "undefined" && | ||
typeof window?.matchMedia === "function") { | ||
if (typeof window !== "undefined" && typeof window?.matchMedia === "function") { | ||
return window.matchMedia(query).matches; | ||
@@ -33,0 +32,0 @@ } |
{ | ||
"name": "@einride/hooks", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"description": "Reusable React hooks", | ||
@@ -16,22 +16,22 @@ "main": "./lib/main.js", | ||
"devDependencies": { | ||
"@commitlint/cli": "17.0.1", | ||
"@commitlint/config-conventional": "17.0.0", | ||
"@einride/eslint-plugin": "6.0.0", | ||
"@einride/prettier-config": "1.2.0", | ||
"@commitlint/cli": "17.0.3", | ||
"@commitlint/config-conventional": "17.0.3", | ||
"@einride/eslint-plugin": "6.7.0", | ||
"@einride/prettier-config": "2.0.0", | ||
"@einride/tsconfig": "1.0.0", | ||
"@testing-library/jest-dom": "5.16.4", | ||
"@testing-library/react": "13.2.0", | ||
"@types/react": "18.0.9", | ||
"@types/react-dom": "18.0.5", | ||
"@vitejs/plugin-react": "1.3.2", | ||
"concurrently": "7.2.1", | ||
"eslint": "8.16.0", | ||
"jsdom": "19.0.0", | ||
"prettier": "2.6.2", | ||
"react": "18.1.0", | ||
"react-dom": "18.1.0", | ||
"semantic-release": "19.0.2", | ||
"typescript": "4.7.2", | ||
"vite": "2.9.9", | ||
"vitest": "0.12.9" | ||
"@testing-library/jest-dom": "5.16.5", | ||
"@testing-library/react": "13.3.0", | ||
"@types/react": "18.0.17", | ||
"@types/react-dom": "18.0.6", | ||
"@vitejs/plugin-react": "2.0.1", | ||
"concurrently": "7.3.0", | ||
"eslint": "8.22.0", | ||
"jsdom": "20.0.0", | ||
"prettier": "2.7.1", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"semantic-release": "19.0.3", | ||
"typescript": "4.7.4", | ||
"vite": "3.0.7", | ||
"vitest": "0.21.1" | ||
}, | ||
@@ -38,0 +38,0 @@ "peerDependencies": { |
@@ -21,4 +21,3 @@ # @einride/hooks | ||
Take a look in the | ||
[hooks folder](https://github.com/einride/hooks/tree/main/src/hooks) to see | ||
Take a look in the [hooks folder](https://github.com/einride/hooks/tree/main/src/hooks) to see | ||
available hooks. | ||
@@ -28,4 +27,3 @@ | ||
See | ||
[Contributing Guide](https://github.com/einride/hooks/blob/main/CONTRIBUTING.md). | ||
See [Contributing Guide](https://github.com/einride/hooks/blob/main/CONTRIBUTING.md). | ||
@@ -32,0 +30,0 @@ ## License |
9842
137
31