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;
};