stremio-web/src/common/useLocationHash.js
2019-08-29 13:10:48 +03:00

17 lines
536 B
JavaScript

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