useRouteChange
🏹 detect when react router dom route changes
get started
We provide two way of using this package single
or multi
:
npm i @snappmarket/use-route-change
OR
npm i @snappmarket/hooks
usage
import useRouteChange from '@snappmarket/use-route-change';
// or
// import { useRouteChange } from '@snappmarket/hooks';
const MyComponenet = props => {
useRouteChange(() => {
// do sth here
});
};
source code
import { useState, useEffect } from 'react';
/**
* Debounce setting a value
* @param value
* @param delay
* @returns {[string, fn, fn]}
*/
export default function useDebounce(value, delay) {
// State and setters for debounced value
const [debouncedValue, setDebouncedValue] = useState(value);
let handler;
const canceller = () => {
clearTimeout(handler);
};
useEffect(() => {
handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);
return canceller;
}, [value]);
return [debouncedValue, canceller, setDebouncedValue];
}