mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 03:45:59 +00:00
18 lines
381 B
JavaScript
18 lines
381 B
JavaScript
// copied from https://usehooks.com/usePrevious/
|
|
|
|
import React from 'react';
|
|
|
|
export default function usePrevious(value) {
|
|
const ref = React.useRef();
|
|
|
|
// Store current value in ref
|
|
|
|
React.useEffect(() => {
|
|
ref.current = value;
|
|
}, [value]); // Only re-run if value changes
|
|
|
|
// Return previous value (happens before update in useEffect above)
|
|
|
|
return ref.current;
|
|
}
|