0
  1. Why this.getAccount() doesn't return my json from fetch?.
  2. With callback this.getAccount(function ($) { return $ }) still doesn't work.

React Component

  getAccount () {
    fetch('http://192.168.1.2:3000/account', {
      method: 'POST'
    }).then(function ($) {
      return $.json()
    }).then(function ($) {
      return $
    })
  }
  render () {
    return (
      <div>
        {
          this.getAccount()
        }
      </div>
    )
  }
Community
  • 1
  • 1
Altaula
  • 774
  • 1
  • 7
  • 22
  • 1
    `getAccount` returns `undefined` in your code because there is no return from `getAccount` - once you fix that, then the only thing it can return is a Promise, it can not return an asynchronous value synchronously – Jaromanda X Feb 10 '17 at 01:13
  • @JaromandaX So it's impossible to do? – Altaula Feb 10 '17 at 01:21
  • I didn't say that - see the question this is marked as a duplicate of – Jaromanda X Feb 10 '17 at 01:32

0 Answers0