Fix broker statistic updates

This commit is contained in:
Thomas Nordquist
2019-07-17 15:56:38 +02:00
parent b33412504d
commit f2d632959b
2 changed files with 19 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import * as q from '../../../../backend/src/Model'
import { useEffect, useState } from 'react'
export function useUpdateComponentWhenNodeUpdates(node?: q.TreeNode<any>): number {
const [lastUpdate, setLastUpdate] = useState(0)
useEffect(() => {
if (!node) {
return
}
const updateComponent = () => setLastUpdate(Date.now())
node.onMerge.subscribe(updateComponent)
return function cleanup() {
node.onMerge.unsubscribe(updateComponent)
}
}, [node])
return lastUpdate
}