npm-pkg-hook 1.11.2 → 1.11.3

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.
package/package.json CHANGED
@@ -10,7 +10,6 @@
10
10
  "react": "18.1.0",
11
11
  "react-dom": "18.1.0",
12
12
  "react-query": "^3.39.2",
13
- "react-responsive": "^10.0.0",
14
13
  "xlsx": "0.18.5"
15
14
  },
16
15
  "description": "description-pkg-hook",
@@ -46,5 +45,5 @@
46
45
  "rm": "rm -rf node_modules package-lock.json && npm i",
47
46
  "test": "echo \"Error: no test specified\" && exit 1"
48
47
  },
49
- "version": "1.11.2"
48
+ "version": "1.11.3"
50
49
  }
@@ -1,16 +1,35 @@
1
- import { useMediaQuery } from 'react-responsive'
1
+ import { useEffect, useState } from 'react'
2
2
 
3
3
  export const MEDIA_QUERY = {
4
- MOBILE: '768px',
5
- TABLED: '960px'
4
+ MOBILE: '(max-width: 768px)',
5
+ TABLET: '(max-width: 960px)'
6
6
  }
7
7
 
8
8
  export const useMobile = () => {
9
- const isMobile = useMediaQuery({ query: `(max-width: ${MEDIA_QUERY.MOBILE})` })
10
- const isTablet = useMediaQuery({ query: `(max-width: ${MEDIA_QUERY.TABLED}})` })
9
+ const [isMobile, setIsMobile] = useState(false)
10
+ const [isTablet, setIsTablet] = useState(false)
11
11
 
12
- return {
13
- isMobile,
14
- isTablet
15
- }
12
+ useEffect(() => {
13
+ if (typeof window === 'undefined') return
14
+
15
+ const mobileQuery = window.matchMedia(MEDIA_QUERY.MOBILE)
16
+ const tabletQuery = window.matchMedia(MEDIA_QUERY.TABLET)
17
+
18
+ const updateMatches = () => {
19
+ setIsMobile(mobileQuery.matches)
20
+ setIsTablet(tabletQuery.matches)
21
+ }
22
+
23
+ updateMatches() // inicializa
24
+
25
+ mobileQuery.addEventListener('change', updateMatches)
26
+ tabletQuery.addEventListener('change', updateMatches)
27
+
28
+ return () => {
29
+ mobileQuery.removeEventListener('change', updateMatches)
30
+ tabletQuery.removeEventListener('change', updateMatches)
31
+ }
32
+ }, [])
33
+
34
+ return { isMobile, isTablet }
16
35
  }