blob: 124bb40a2a3ef4f1b02540180a95fa9be40f71aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { useRef, useEffect } from 'react';
export const usePrevious = (value) => {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
};
/* eslint-disable */
export const useEffectAsync = (effect, deps) => {
const ref = useRef();
useEffect(() => {
effect().then((result) => ref.current = result);
return () => {
const result = ref.current;
if (result) {
result();
}
};
}, deps);
};
|