mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-19 22:12:13 +00:00
NavBarButton reacts to hash changes
This commit is contained in:
parent
ad827d19bd
commit
bd949bca74
1 changed files with 10 additions and 1 deletions
|
|
@ -6,7 +6,16 @@ const styles = require('./styles');
|
|||
|
||||
const NavBarButton = ({ className, icon, label, href, onClick }) => {
|
||||
const type = typeof onClick === 'function' ? 'button' : 'link';
|
||||
const active = window.location.hash === href;
|
||||
const [active, setActive] = React.useState(window.location.hash === href);
|
||||
const onHashChanged = React.useCallback(() => {
|
||||
setActive(window.location.hash === href);
|
||||
}, [href]);
|
||||
React.useEffect(() => {
|
||||
window.addEventListener('hashchange', onHashChanged);
|
||||
return () => {
|
||||
window.removeEventListener('hashchange', onHashChanged);
|
||||
};
|
||||
}, []);
|
||||
return (
|
||||
<Input className={classnames(className, styles['button'], { 'active': active })} type={type} href={href} onClick={onClick}>
|
||||
<Icon className={styles['icon']} icon={icon} />
|
||||
|
|
|
|||
Loading…
Reference in a new issue