Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!