Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/targets/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@ export function useReduceMotion() {
setMatch(mq.matches);
};
handleChange();
mq.addEventListener('change', handleChange);
// If only has depreciated api use that, otherwise use current api
// Safari 14 + has both, Safari <= 13 only has depreciated
// fixes https://github.com/infiniteluke/react-reduce-motion/issues/8
const usesDepreciatedApi = mq.addListener && !mq.addEventListener;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depreciated or deprecated?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitchellwarr Golly I've been saying that wrong a while! Thanks! 🙈 ❤️

if (usesDepreciatedApi) {
mq.addListener(handleChange);
} else {
mq.addEventListener('change', handleChange);
}
return () => {
mq.removeEventListener('change', handleChange);
if (usesDepreciatedApi) {
mq.removeListener(handleChange);
} else {
mq.removeEventListener('change', handleChange);
}
};
}, []);
return matches;
Expand Down