Convert Promise to data I am trying to convert my use state to use reducer. an async function is calling to fetch data and I'm not abale to use it in the reducer here is part of the code:
switch (action.type) {
case "load":
const data = loadTodos()
state = { ...state, todos: [...data] };
return state;
}}
async function loadTodos() {
return await todoService.getTodo();
}
I tried to solve the problem in this way :
var myState = []
loadTodos().then((data) => {
myState = [...data];
});
console.log(myState);
` myState is correct inside .then scope but outside is empty array.