@kotaro@kotaro.me
I was so foolish today. It all happened in just a few hours, but it’s already become an embarrassing memory.
In JavaScript, when you’re inside an async function and want to store JSON received from a server, you assign it like this: const data = await response.json(). You do this because response.json() returns a Promise, and you can’t get the actual data without using await.
I didn’t forget that part. In fact, I was so careful that I even kept using await on the data after storing it in a variable, like selectedMonsterData = await data. I thought I had a solid grasp of JavaScript fundamentals.
But when I called the async function that contains fetch from a different button’s click event listener, I forgot to use await. To be precise, I forgot how to declare an event listener as async. So I never even thought to add await before calling the function that runs fetch.
Because of that, the front end didn’t wait for the necessary data after I clicked the button to send a POST request to the server, and that caused a null error.
Overconfidence can delay projects. My mistake today only cost me a day, but it made me reflect deeply.