Skip to content

Huge problem: code does not go further than await

dieldore profile image Dieldore github logo ・1 min read

Code in App.js

componentDidMount() {
async getAccountData() {
    try {
      let FD = new FormData();
      FD.append('test', true);
      let Q = fetch('/ajax/get', {
        method: 'POST',
        body: FD
      let data = await Q.json();
    catch(e) {

After await is called, it gets the data in JSON. But if you put console.log after it, then they do not work, so setState also breaks my application. debugger also does not work there.
I am using firefox 68.6 and 80.0.3987.132

twitter logo DISCUSS (2)
markdown guide

You have to await Q and then execute .json() on the result. fetch() returns a promise that can be awaited.

Would probably go for something like:

 let Q = await fetch('/ajax/get', {
  method: 'POST',
  body: FD
let data = await Q.json();

Read 4th parahraph under Concepts and usage:


Thank you, just noticed. In a hurry forgot to specify await

Classic DEV Post from Jul 30 '19

PublishTo.Dev: Scheduling article publishing on

Dieldore profile image