Skip to content

Commit

Permalink
fix: non-reactive bug above react 18 strict mode (#294)
Browse files Browse the repository at this point in the history
* fix: non-reactive bug above react 18 strict mode

* fix: remove 'ev' optional chaining
  • Loading branch information
ynifamily3 committed May 9, 2022
1 parent 30dcc05 commit 795942d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/useMediaQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ const useMatches = (mediaQuery: MediaQueryList): boolean => {
const [ matches, setMatches ] = React.useState<boolean>(mediaQuery.matches)

React.useEffect(() => {
const updateMatches = () => {
setMatches(mediaQuery.matches)
const updateMatches = (ev: MediaQueryListEvent) => {
setMatches(ev.matches)
}
mediaQuery.addListener(updateMatches)
updateMatches()
setMatches(mediaQuery.matches)

return () => {
mediaQuery.removeListener(updateMatches)
Expand Down

0 comments on commit 795942d

Please sign in to comment.