Message from JavaScript discussions

March 2019

— Clapped


I am assigning the result of an api request to state but it is not showing. Response. Data. Items array has a length 5 while state still has 0

— Can anybody tell me what's wrong

— The response is not the data directly.

— You need something like

const data = await response.json()

— Https://

— I am using axis for performing requests

— Axios

— Also, setState is not a property you can set.

— So how do i resolve this?

— And setState is not a synchronous function, so you can’t assure this.state is modified at the next line.

Message permanent page

— Thanks Christian