mirror of
https://github.com/khairul169/github-leaderboard.git
synced 2026-09-17 09:53:21 +07:00
feat: add view leaderboard item
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const setHashUrl = (value: string) => {
|
||||
history.replaceState(undefined, undefined as never, "#" + value);
|
||||
window.dispatchEvent(new HashChangeEvent("hashchange"));
|
||||
};
|
||||
|
||||
export const useHashUrl = () => {
|
||||
const [value, setValue] = useState(location.hash.substring(1));
|
||||
|
||||
useEffect(() => {
|
||||
const onHashChange = () => {
|
||||
setValue(location.hash.substring(1));
|
||||
};
|
||||
|
||||
window.addEventListener("hashchange", onHashChange);
|
||||
return () => window.removeEventListener("hashchange", onHashChange);
|
||||
}, []);
|
||||
|
||||
return value;
|
||||
};
|
||||
Reference in New Issue
Block a user