0.2.5 • Published 5 years ago
@snappmarket/use-route-change v0.2.5
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];
}
0.2.5
5 years ago
0.2.3-beta.quq9rbw
5 years ago
0.2.3-beta.4cbesil
5 years ago
0.2.3-beta.qaoe83s
5 years ago
0.2.3
5 years ago
0.2.1-beta.cswtgmi
5 years ago
0.1.24
5 years ago
0.2.1-alpha.0
5 years ago
0.1.22
5 years ago
0.1.21
5 years ago
0.1.20
5 years ago
0.1.10
5 years ago
0.1.11
5 years ago
0.1.13
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago