mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
re-structure to monorepo.
This commit is contained in:
16
packages/webapp/src/hooks/utils/usePrevious.tsx
Normal file
16
packages/webapp/src/hooks/utils/usePrevious.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
// @ts-nocheck
|
||||
import { useRef, useEffect } from 'react';
|
||||
|
||||
|
||||
// Hook
|
||||
export function usePrevious(value) {
|
||||
// The ref object is a generic container whose current property is mutable ...
|
||||
// ... and can hold any value, similar to an instance property on a class
|
||||
const ref = useRef();
|
||||
// Store current value in ref
|
||||
useEffect(() => {
|
||||
ref.current = value;
|
||||
}, [value]); // Only re-run if value changes
|
||||
// Return previous value (happens before update in useEffect above)
|
||||
return ref.current;
|
||||
}
|
||||
Reference in New Issue
Block a user