Skip to content

Commit

Permalink
Migrate usePrevious to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
kowczarz committed Oct 6, 2023
1 parent 5fcdfd9 commit 35ed423
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/hooks/usePrevious.js → src/hooks/usePrevious.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import {useEffect, useRef} from 'react';

/**
* A hook that returns the previous value of a variable
*
* @param {*} value
* @returns {*}
*/
export default function usePrevious(value) {
const ref = useRef(value);
export default function usePrevious<T>(value: T): T {
const ref = useRef<T>(value);
useEffect(() => {
ref.current = value;
}, [value]);
Expand Down

0 comments on commit 35ed423

Please sign in to comment.