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>
);
}
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.