add new notes, fix gh-pages

This commit is contained in:
Fedor Katurov 2023-12-28 00:23:55 +07:00
parent 2af996c99c
commit c4c6aa2294
3 changed files with 87 additions and 4 deletions

View file

@ -0,0 +1,28 @@
```typescript
import { useEffect, useRef } from 'react';
/** Pass dictionary of `props` as argument and it will
* tell you, which one changed after rerender.
* Use `prefix` to distinguish props of different components.
*/
export const useWhatsChanged = (
props: Record<string, unknown>,
prefix = '',
) => {
const prevProps = useRef(props);
useEffect(() => {
Object.entries(props).forEach(([key, value]) => {
if (
!Object.prototype.hasOwnProperty.call(prevProps.current, key) ||
prevProps.current[key] !== value
) {
console.log(`${prefix} ${key} has changed`);
}
});
prevProps.current = props;
}, [props, prefix]);
};
```