Skip to content

Commit

Permalink
feat: useMedia - initialize state with call to media query (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich authored Jul 11, 2019
2 parents c4f5f16 + eeb55e4 commit ab81897
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/useMedia.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit ab81897

Please sign in to comment.