ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function StatusBarProvider

    • Context provider for the status bar. Holds the current message and exposes setStatusText / flashStatusText (the latter auto-clears via a timer) to descendants through useStatusBar.

      Parameters

      • props: { children: ReactNode }

        The provider props.

        • children: ReactNode

          The subtree that can read and update the status bar.

      Returns Element

      The provider wrapping children.

      <StatusBarProvider>
      <App />
      <StatusBar />
      </StatusBarProvider>
      export function StatusBarProvider({ children }: { children: ReactNode }) {
      const [statusText, setStatusText] = useState<string | null>(null);
      const flashTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);

      const flashStatusText = useCallback((text: string, durationMs = 1000) => {
      if (flashTimerRef.current) {
      clearTimeout(flashTimerRef.current);
      }
      setStatusText(text);
      flashTimerRef.current = setTimeout(() => {
      setStatusText(null);
      flashTimerRef.current = null;
      }, durationMs);
      }, []);

      return (
      <StatusBarContext.Provider value={{ statusText, setStatusText, flashStatusText }}>
      {children}
      </StatusBarContext.Provider>
      );
      }