Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
How to show temporary message in ReactJS until API endpoint comes back

In my helperfile.js file, I have an react bootstrap and overlay trigger as follows. The flaskResult variable is a prop that is passed in.

  const popover = (
    <Popover id="popover-basic">
      <Popover.Header as="h3">Num Nodes</Popover.Header>
      <Popover.Body>
        The number of nodes is: {flaskResult}
      </Popover.Body>
    </Popover>
  );
...
          <OverlayTrigger rootClose trigger="click" placement="left" overlay={popover}>
            <Button variant="outline-primary"  onClick = { (e) => {onCallEndpoint({endpoint:"get_num_nodes"})}} >Count Num Nodes</Button>
          </OverlayTrigger>

Notice that the Button calls an onCallEndpoint. That endpoint hits a flask API to do some computations. Some computations are very quick and the result is almost instant. Others are very slow and the result takes several seconds.

How would I show "processing" or a spinning circle while flask executes?

Here's the api call in app.js

  const onCallEndpoint = async (props) => {
    const {endpoint} = props;
    try {
        const flow = reactFlowInstance.toObject();
        const token = await getAccessTokenSilently();
        const response = await fetch(
          `${serverUrl}/${props.endpoint}`,
          {
            headers: {
             'Content-Type': 'application/json',
              Authorization: `Bearer ${token}`,
            },
            method: 'POST',
            body:JSON.stringify(flow),
          }
        );
  
        const responseData = await response.json();
        setFlaskResult(responseData.message);
      } catch (error) {
        setFlaskResult(error.message);
      }
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If this helps anyone:

I overloaded the API call:

  const onCallEndpoint = async (props) => {
    const {endpoint} = props;
    setFlaskResult(null);
    try {
        const flow = reactFlowInstance.toObject();
        const token = await getAccessTokenSilently();
        const response = await fetch(
          `${serverUrl}/${props.endpoint}`,
          {
            headers: {
             'Content-Type': 'application/json',
              Authorization: `Bearer ${token}`,
            },
            method: 'POST',
            body:JSON.stringify(flow),
          }
        );
  
        const responseData = await response.json();
        
        setFlaskResult(responseData.message);
      } catch (error) {
        setFlaskResult(error.message);
      }
};

Then in popover I did the following:

 const popover = (
    <Popover id="popover-basic">
      <Popover.Header as="h3">Num Nodes</Popover.Header>
      <Popover.Body>
      The number of nodes is: {(flaskResult) ? flaskResult:"Computing!"}.
        
      </Popover.Body>
    </Popover>
  );
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda