* Migrate article channel names Hide sidebar on small screens PoC sidebar Lazy load sidebar Fix background Fix ad link Add articles with no images Create top bar Styling improvements Sidebar color tweaks Sidebar color tweaks Make buttons nicer * Same top level headings * Remove sidebar title * Monochrome news icon on peeking card * Fix peek button not showing on empty feeds * Heading cleanup
24 lines
746 B
TypeScript
24 lines
746 B
TypeScript
// Copyright (c) 2024 The Brave Authors. All rights reserved.
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
export default function useMediaQuery(query: string) {
|
|
const [result, setResult] = useState(() => window.matchMedia(query).matches)
|
|
|
|
useEffect(() => {
|
|
const media = window.matchMedia(query)
|
|
const handler = () => setResult(media.matches)
|
|
media.addEventListener('change', handler)
|
|
setResult(media.matches)
|
|
|
|
return () => {
|
|
media.removeEventListener('change', handler)
|
|
}
|
|
}, [query])
|
|
|
|
return result
|
|
}
|