0.2.5 • Published 5 years ago
@snappmarket/use-did-update-effect v0.2.5
useDidUpdateEffect
🧵 do not worry about render phase effect calls
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);
};
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.23
5 years ago
0.2.1-alpha.0
5 years ago
0.1.21
5 years ago
0.1.20
5 years ago
0.1.19
5 years ago
0.1.10
5 years ago
0.1.12
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago
0.0.7
5 years ago