0

I want to fetch data from firebase. first await function is getting VALUE from database and second await function is getting data, which its object value is less or more than VALUE. How to tell javascript when finish the first await function and then start to execute second second await function?

React.useEffect(() => {
      const catchValue = async () => {}
      const catchDatabyValue = async () => {}

}, []);
  • 1
    I guess you want to 'chain' async functions. not await. .Does this answer your question? [Chain async functions](https://stackoverflow.com/questions/38644754/chain-async-functions) – Mihai T Nov 23 '21 at 08:23

1 Answers1

2

Wrap the function calls in an async function, and await the results of calling them.

useEffect(() => {
  async function getData() {
    const value = await catchValue();
    const data = await catchDatabyValue(value);
  }
  getData();
}, []);
Andy
  • 61,948
  • 13
  • 68
  • 95