mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-22 13:01:27 +03:00
18 lines
447 B
JavaScript
18 lines
447 B
JavaScript
import { useRef, useEffect } from 'react'
|
|
|
|
export function useTraceUpdate(props) {
|
|
const prev = useRef(props)
|
|
useEffect(() => {
|
|
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
|
|
if (prev.current[k] !== v) {
|
|
ps[k] = [prev.current[k], v]
|
|
}
|
|
return ps
|
|
}, {})
|
|
if (Object.keys(changedProps).length > 0) {
|
|
console.log('Changed props:', changedProps)
|
|
}
|
|
prev.current = props
|
|
})
|
|
}
|