Skip to content
Open
Changes from all 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 deprecated api use that, otherwise use current api
// Safari 14 + has both, Safari <= 13 only has deprecated
// fixes https://github.com/infiniteluke/react-reduce-motion/issues/8
const usesDeprecatedApi = mq.addListener && !mq.addEventListener;
if (usesDeprecatedApi) {
mq.addListener(handleChange);
} else {
mq.addEventListener('change', handleChange);
}
return () => {
mq.removeEventListener('change', handleChange);
if (usesDeprecatedApi) {
mq.removeListener(handleChange);
} else {
mq.removeEventListener('change', handleChange);
}
};
}, []);
return matches;
Expand Down