This package has been deprecated

Author message:

Please use @snappmarket/hooks instead

@snappmarket/use-did-update-effect

0.2.5 • Public • Published

useDidUpdateEffect

🧵 do not worry about render phase effect calls


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-did-update-effect
OR
npm i @snappmarket/hooks

usage

import useDidUpdateEffect from '@snappmarket/use-did-update-effect';
// or 
// import { useDidUpdateEffect } from '@snappmarket/hooks';


const MyComponenet = props => {
  /**
   * Do not run on render
   */
  useDidUpdateEffect(() => {
    // I will run only when my dependencies update
  }, [deps]);
};

source code

import { useRef, useEffect } from 'react';

/**
 * Calls function on component update or inputs change phase
 * @param fn
 * @param inputs
 */
export default (fn, inputs) => {
  const didMountRef = useRef(false);

  useEffect(() => {
    if (didMountRef.current) fn();
    else didMountRef.current = true;
  }, inputs);
};

Package Sidebar

Install

npm i @snappmarket/use-did-update-effect

Weekly Downloads

1

Version

0.2.5

License

MIT

Unpacked Size

6.88 kB

Total Files

7

Last publish

Collaborators

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