This package has been deprecated

Author message:

Please use @snappmarket/hooks instead

@snappmarket/use-route-change

0.2.5 • Public • Published

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];
}

/@snappmarket/use-route-change/

    Package Sidebar

    Install

    npm i @snappmarket/use-route-change

    Weekly Downloads

    2

    Version

    0.2.5

    License

    MIT

    Unpacked Size

    6.79 kB

    Total Files

    6

    Last publish

    Collaborators

    • jrjs
    • mahsamesbah
    • milad.kiani
    • mostafa_rastegar
    • rezaerami