2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2021-09-17 22:24:21 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { useRef } from 'react';
|
|
|
|
|
|
|
|
export function usePrevious<T>(initialValue: T, currentValue: T): T {
|
|
|
|
const previousValueRef = useRef<T>(initialValue);
|
|
|
|
const result = previousValueRef.current;
|
|
|
|
previousValueRef.current = currentValue;
|
|
|
|
return result;
|
|
|
|
}
|