I am using React useReducer and trying to display the information taken from firebase.
async function reducer(listState, action) {
switch (action.type) {
case "load":
let stateCopy2 = [...listState];
let result = await firebase.firestore().collection("contractors").doc(action.idList[0].id).get()
console.log("non promise/ console log 1",result.data())
return [...stateCopy2, result.data()]
default:
throw new Error();
}
}
function Thing(props) {
return (
<div >
{listState.map((data, index) => (
<div>
{data.Bio}
</div>
))}
<button onClick={()=>console.log("promise/ console log 2", listState)}>check</button>
</div>
)
}
export default Thing;
when doing the console.log(listState); at console.log 1 the information shows what it should. Just what it should:
{BIo:"hello"}
at console.log 2 the information it shows is:
Promise {<fulfilled>: Array(2)}
with the original information shown in there.
after the transformation, as listState is the promise it cannot be mapped though.
How would I turn the promise into just the array or not let it appear as this?