mirror of
https://github.com/thomasnordquist/MQTT-Explorer.git
synced 2026-09-11 17:13:53 +00:00
16 lines
598 B
TypeScript
16 lines
598 B
TypeScript
import { Props } from '..'
|
|
import { useEffect, useState } from 'react'
|
|
|
|
export function useIsAllowedToAutoExpandState(props: Props): boolean {
|
|
const { settings, treeNode, isRoot } = props
|
|
const [isAllowedToAutoExpand, setAllowAutoExpand] = useState(false)
|
|
|
|
useEffect(() => {
|
|
const newIsAllowedToAutoExpand = isRoot || treeNode.edgeCount() <= settings.get('autoExpandLimit')
|
|
if (newIsAllowedToAutoExpand !== isAllowedToAutoExpand) {
|
|
setAllowAutoExpand(newIsAllowedToAutoExpand)
|
|
}
|
|
}, [treeNode.edgeCount(), settings.get('autoExpandLimit')])
|
|
return isAllowedToAutoExpand
|
|
}
|