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
@cassidoo
cassidoo / useMedia.jsx
Last active October 27, 2022 16:13
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)