mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
useMedia - initialize state with call to media query
Initializing state with result from call to window.matchMedia avoids possible initial flicker of returned value, when media query matched initially
This commit is contained in:
parent
c4f5f16120
commit
eeb55e4927
@ -1,7 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
const useMedia = (query: string, defaultState: boolean = false) => {
|
||||
const [state, setState] = useState(defaultState);
|
||||
const useMedia = (query: string) => {
|
||||
const [state, setState] = useState(() => window.matchMedia(query).matches);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user