stremio-web/src/common/useLocationHash.js
2019-05-16 18:39:48 +03:00

17 lines
539 B
JavaScript

const React = require('react');
const useLocationHash = () => {
const [locationHash, setLocationHash] = React.useState(window.location.hash);
React.useEffect(() => {
const onLocationHashChanged = () => {
setLocationHash(window.location.hash);
};
window.addEventListener('hashchange', onLocationHashChanged);
return () => {
window.removeEventListener('hashchange', onLocationHashChanged);
};
}, []);
return locationHash;
};
module.exports = useLocationHash;