Map() item going through multiple requests

Asked

Viewed 34 times

0

The code below worked the way I wanted but in the last test something went wrong. I do a map where the item went through several requests and at the end I defined my object and then a new item would scan the functions. Now, for some reason for each function map, always updating my state to each item.

getData() {
    array((item, index) => {
        if (item.x.length <= 11 && ((item.y == 8) || (item.y == 9))) {
            Requisição1(x, y).then((res) => {
                let data = (res.data ? res.data : []);
                this.setState({ state1: data }, () => {

                    Requisição2(x, y).then((res) => {
                        let data = (res.data ? res.data : []);
                        this.setState({ state2: data }, () => {


                            Requisição3(x, y).then((res) => {
                                let data = (res.data ? res.data : []);
                                this.setState({ state3: data }

                             let vendedor = {
                                                    dadosPessoa: this.state.sate1,
                                                    dadosTelefone: this.state.state2,
                                                    dadosEmail: this.state.state3,
                                                       }
                                                this.state.x.push(vendedor);
                                                this.setState({ sellerx: this.state.x });

                                            })

                                        })
                                    })
                                })
                            })
                        })
                    }
                    )
                })
            }
            )
  • Share the error message you received. Edit the question and add to it.

  • I get no error, just don’t go through all functions per item... It’s like every function calls a map.

  • In vendedor are you using the state you changed in previous requests? Do these requests have to be sequential? They cannot be in parallel?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.