import React, { useState, useEffect } from "react"; import PropTypes from "prop-types"; import { Redirect } from "react-router-dom"; import { useServerApi } from "../api"; const ServerAvailabilityProvider = ({ children }) => { const [ok, setOk] = useState(null); const { checkHealth } = useServerApi(); useEffect(() => { checkHealth({ onCompleted: () => setOk(true), onError: () => setOk(false) }); }, [checkHealth]); if (ok === null) return Checking server health...; if (ok === false) return ; return <>{children}; }; ServerAvailabilityProvider.propTypes = { children: PropTypes.node }; export default ServerAvailabilityProvider;