Skip to content

Commit

Permalink
Merge pull request #29019 from software-mansion-labs/ts-migration/use…
Browse files Browse the repository at this point in the history
…-previous

[No QA][TS migration] Migrate 'usePrevious.js' hook to TypeScript
  • Loading branch information
techievivek authored Oct 10, 2023
2 parents a63f853 + 35ed423 commit 67a2024
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 67a2024

Please sign in to comment.