useState and promises

#1

I’m trying to code useState variables with promises and it won’t work. When you use set state with a query, you can’t use await in an async function. Is there a better method of setting a promise in a useState variable and processing in an async function?

const [test, setTest] = useState();

useEffect(() => {
  client.query(...).then(query => {
    // setProcess returns a promise 
    let process = setProcess(query);
    setTest(process);     
  });
});

areaTest = async(test) => {
  // the data appear from the promise
  let data = await test;
}; 

#2

You have to nest an async method:

useEffect(() => {
  async function fetchMyAPI() {
    let url = 'http://something';
    let config = {};
    const response = await myFetch(url);
    console.log(response);
  }  

  fetchMyAPI();
}, []);