0.2.5 • Published 5 years ago

@snappmarket/use-route-change v0.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

useRouteChange

🏹 detect when react router dom route changes

version downloads PRs Welcome MIT License

Watch on GitHub Star on GitHub

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

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