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

145
Views
React firebase doesn't await

I want to get data from firebase and map it and render a table with it but the firebase function returns data after the page loads.

    const [datas, setData] = useState();
    var ref = db.ref("something");

  
    useEffect(() => {
      const fetchData = async () => {
        await ref.once("value").then((snapshot) => {
          const fetched = snapshot.val();
          var feed = {'name':'shoe','remark':'remarka','price':'pricea','photo':'photo','amount':'350'};
          console.log('fetched', fetched)
          setData(feed);
        }); 
      };
      fetchData();
    }, []);

now if I make a var here let's say var text= datas and console.log it it will return undefined the feed var is just some dummy text

{dummy.map((data, key) => {
//render table
})

is there any way to make the page wait for the function to finish the useState ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use the AND operator (&&) which only executes the right operand when the left operand is truthy. It is not necessary to make a variable called dummy.

{
  datas && datas.map(data=>{
     console.log(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!