But I do not understand why my state in the first example is set to a Promise. I’m new to get requests and async functions, so I would really appreciate it if someone could help me out here.
This line is not doing what you want it to do. I believe you can only use await this way inside of a JS module. So your function is returning before the axios promise is resolved (it’s as if await is not there at all) and the value of cards at that time is a pending promise.
Regardless, I think you are much better off taking full advantage of async/await and rewriting this to get rid of the next and catch blocks.
There was another post about this recently with the same problem on a mongoose query. The problem is you are mixing await/async and promise resolution with .then()/.catch(), so just pick one. Your working example works for that reason; you picked the promise method. If you prefer async/await, then just do it all that way.
This is a common problem; a fairly common solution is outlined here (this is an async/await version). I routinely use variations of this solution to fetch data in react projects.
I’m going to put this here as an example because I think I can basically write these in my sleep at this point in time, and it’s IMO a good example of why hooks are very useful. I think it’s fairly self-explanatory, though useCallback may not be: I’m using it instead of useEffect so I can return a fetch method from the hook.