优化
This commit is contained in:
11
client/shared/hooks/usePrevious.ts
Normal file
11
client/shared/hooks/usePrevious.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
export function usePrevious<T>(state: T): T | undefined {
|
||||
const ref = useRef<T>();
|
||||
|
||||
useEffect(() => {
|
||||
ref.current = state;
|
||||
});
|
||||
|
||||
return ref.current;
|
||||
}
|
||||
Reference in New Issue
Block a user