Skip to content

Instantly share code, notes, and snippets.

View aggutierrez98's full-sized avatar
🏠
Working from home

Agustin Gutierrez aggutierrez98

🏠
Working from home
View GitHub Profile
@aggutierrez98
aggutierrez98 / useMedia.jsx
Created May 1, 2022 03:56 — forked from cassidoo/useMedia.jsx
An example of checking on a media query with React Hooks
function useMedia(query) {
const [matches, setMatches] = useState(window.matchMedia(query).matches)
useEffect(() => {
const media = window.matchMedia(query)
if (media.matches !== matches) {
setMatches(media.matches)
}
const listener = () => {
setMatches(media.matches)