MCPcopy
hub / github.com/yocontra/react-responsive / useDevice

Function useDevice

src/useMediaQuery.ts:40–56  ·  view source on GitHub ↗
(
  deviceFromProps?: MediaQueryMatchers
)

Source from the content-addressed store, hash-verified

38}
39
40const useDevice = (
41 deviceFromProps?: MediaQueryMatchers
42): Partial<MediaQueryAllQueryable> | undefined => {
43 const deviceFromContext = useContext(Context)
44 const getDevice = () =>
45 hyphenateKeys(deviceFromProps) || hyphenateKeys(deviceFromContext)
46 const [device, setDevice] = useState(getDevice)
47
48 useEffect(() => {
49 const newDevice = getDevice()
50 if (!shallowEqualObjects(device, newDevice)) {
51 setDevice(newDevice)
52 }
53 }, [deviceFromProps, deviceFromContext])
54
55 return device
56}
57
58const useQuery = (settings: MediaQuerySettings) => {
59 const getQuery = () => makeQuery(settings)

Callers 1

useMediaQueryFunction · 0.85

Calls 1

getDeviceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…