UNPKG

@openshift-console/dynamic-plugin-sdk

Version:

Provides core APIs, types and utilities used by dynamic plugins at runtime.

20 lines (19 loc) 794 B
import * as React from 'react'; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore: FIXME out-of-sync @types/react-redux version as new types cause many build errors import { useSelector } from 'react-redux'; /** * Wait until internal models (CRDs) are loaded. * * Note: When loading is 'in flight' (in progress) when the component * that uses this hook is mounted, this hook waits until this is resolved, too. */ export const useModelsLoaded = () => { const ref = React.useRef(false); const loaded = useSelector(({ k8s }) => k8s.getIn(['RESOURCES', 'loaded'])); const inFlight = useSelector(({ k8s }) => k8s.getIn(['RESOURCES', 'inFlight'])); if (!ref.current && loaded && !inFlight) { ref.current = true; } return ref.current; };