mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
fix: useUpdateEffect run on the wrong time
This commit is contained in:
parent
2ccde2f7fa
commit
1d5cd10fe4
@ -3,14 +3,13 @@ import { useEffect, useRef } from 'react';
|
||||
const useUpdateEffect: typeof useEffect = (effect, deps) => {
|
||||
const isInitialMount = useRef(true);
|
||||
|
||||
useEffect(
|
||||
isInitialMount.current
|
||||
? () => {
|
||||
isInitialMount.current = false;
|
||||
}
|
||||
: effect,
|
||||
deps
|
||||
);
|
||||
useEffect(() => {
|
||||
if (isInitialMount.current) {
|
||||
isInitialMount.current = false;
|
||||
} else {
|
||||
effect();
|
||||
}
|
||||
}, deps);
|
||||
};
|
||||
|
||||
export default useUpdateEffect;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user