Skip to content

Commit

Permalink
useWhyDidYouUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-schrammel committed May 28, 2024
1 parent d408dfe commit d9a4da5
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect, useRef } from 'react';

/**
Expand All @@ -11,7 +12,7 @@ import { useEffect, useRef } from 'react';
*
* @link https://usehooks.com/useWhyDidYouUpdate/
*/
export default function useWhyDidYouUpdate(name, props) {
export default function useWhyDidYouUpdate(name: string, props: Record<string, any>) {
// Get a mutable ref object where we can store props ...
// ... for comparison next time this hook runs.
const previousProps = useRef() as any;
Expand All @@ -21,7 +22,7 @@ export default function useWhyDidYouUpdate(name, props) {
// Get all keys from previous and current props
const allKeys = Object.keys({ ...previousProps.current, ...props });
// Use this object to keep track of changed props
const changesObj = {};
const changesObj: Record<string, any> = {};
// Iterate through keys
allKeys.forEach(key => {
// If previous is different from current
Expand Down

0 comments on commit d9a4da5

Please sign in to comment.