E
E
ekety2020-05-02 22:24:52
Android
ekety, 2020-05-02 22:24:52

Please help with ajax request in React Native. How to make it so that after the first ajax request I get the player's id?

Please help with ajax request in React Native. It turns out that I implemented such a thing that after I enter the player’s nickname into the input, such a thing is executed that the entered nickname (FIG No. 1) is substituted in the ajax url of the request and I get his data (nickname, id, last login), and also its id and write everything in the state and render the component. But then I need to take the player's id from this request, insert it into the url of the second ajax request (FIG No. 2) and after that I already get other data and in them I can already get even more data about the user (what guild he belongs to, offline he or not) and write all this in state. Yes, I implemented all this, but when I write data to the state after the second ajax request and then return it to the component, then my request is displayed on the screen (I requested the status of the player. Is it offline or not). Everything seems to be normal (FIG. No. 3). But after a while, the error Unhandled Rejection (TypeError): Cannot read property 'message' of undefined is displayed and when I try to display the result in the console, it turns out that it is displayed more than 59 times and returns an error (FIG. No. 4). It turns out at me the request is fulfilled 59 times. And this is exactly after I add data to the state. Please help me with this please. Tell me what to do
If necessary, I can upload the code to the git so that it can be edited. I've been struggling with this for a very long time and don't know how to solve it.
Thank you very much for your help

FIGURE 1 - 5eadc34049829588418997.png

FIGURE 2 - 5eadc34863f47420033961.png

FIGURE 3 - 5eadc3512224c486380190.png

FIGURE 4 -5eadc357621d2497443729.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick, 2020-05-07
@ekety

setState cannot be called in the render method, a loop will occur

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question