@proca/widget
Version:
Proca is an open-source campaign toolkit designed to empower activists and organisations in their digital advocacy efforts. It provides a flexible and customisable platform for creating and managing online petitions, email campaigns, and other forms of di
29 lines (22 loc) • 546 B
JavaScript
import { useEffect } from "react";
let hasRun = false;
export const getHash = prefix => {
if (!prefix) {
prefix = "proca_";
}
const urlHash = window.location.hash.substring(1);
if (urlHash.startsWith(prefix)) {
return urlHash.replace(prefix, "");
}
};
const useHash = ({ prefix, onChange }) => {
useEffect(() => {
if (hasRun) return;
hasRun = true;
window.addEventListener("hashchange", () => {
const step = getHash(prefix);
if (step) onChange(step);
});
}, []);
};
export default useHash;