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

215
Vistas
How can I restrict whole page to re-render in React?

I have js file which contains data that I am rendering on the page using useState. I have a button Display which uses fetch API to get more data and display below the existing data.

I would like to display Loading when Display button is clicked till data arrives.

Problem is whole page is re rendered with Loading. I would like to display data that I am getting from js file as it is and just display Loading below Display button till I get more data from API

 const [isLoading, setIsLoading] = useState(false);


  if (isLoading) {
    return <h2>Loading..</h2>;
  }
const fetchData = async () => {
    setIsLoading(true);
    const response = await fetch(fetchDataUrl);
    const data = await response.json();
    setIsLoading(false);
    setMoreData(data.datas);
  };
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const Component = () => {
    const [isLoading, setIsLoading] = useState(false);
    const fetchData = () => {
         setIsLoading(true)
         fetch(someUrl)
            .then(data => {
                setData(data)
                setIsLoading(false)
         });
    }
    return (
    <> 
        {yourData.map((data) => <IdkMaybeItsSomeComponent data={data}>}

        { isLoading  
          ? <h2>Loading...</h2> 
          : <button onClick={fetchData}>Get More Data</button> }
    </>
    )
}

How about something like that? Only showing the loading at the bottom when you are currently loading data.

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