remirror/remirror

View on GitHub
packages/remirror__react-hooks/src/use-previous.ts

Summary

Maintainability
A
2 hrs
Test Coverage
import { useRef } from 'react';

import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect';

export function usePrevious<T>(value: T): T | undefined {
  const ref = useRef<T>();
  useIsomorphicLayoutEffect(() => {
    ref.current = value;
  });
  return ref.current;
}