UNPKG

@openshift-console/dynamic-plugin-sdk

Version:

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

18 lines (17 loc) 635 B
import * as React from 'react'; 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; };