In React.js
if I want to trigger a function when a certain value changes I would use the useEffect
hook and pass it a dependency array containing the value that should cause that function to trigger:
const [myState,setMyState] = useState("some-value");
useEffect(
() => {
someFunctionToTrigger();
}, [theValue]
);
However I'd like to acheive that in pure JavaScript, more specifically I want to know when my location.href
changes so I could call a function every time it changes:
let location_href = location.href;
// everytime location.href changes I want to call a function so I need the equivalent of useEffect
Note that using a Proxy
doesn't work with location