Access data from rest api using reaction

I am developing a reaction application, and I found a big problem, manipulating information from a priori rest.

I have a selection where the api by get method should bring me the client identifier, but I always get this error.

{error: "Client not found"} error: "Client not found"

Error image

I want to get an array with only the identifier of all clients to do this, I do this fetch function, but I don’t know what to add .then ((resposneValue) to get the correct. Map array, but then I get an error, so how the prototyping of the map is not interrupted.

here is my code:

getHistory() {
    const {customer} = this.state
    fetch(
        DOMAIN+'/api/customers/'+customer._id, {
            method: 'get',
            dataType: 'json',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization':'Bearer '+this.props.token
            }
        })
        .then((response) =>
        {
            return response.json();
        })
        .then((responseValue) => {
            /*responseValue.map(function (v) {
                v.platform = v.app ? v.app.platform : null  })*/
            this.setState({customsId:responseValue});
            console.log(responseValue);
        })

}

Edit:

I have one more sample:

getCustomers(){

    fetch(

        DOMAIN+'/api/customers/shop/'+this.props.salon, {
            method: 'get',
            dataType: 'json',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization':'Bearer '+this.props.token
            }
        })
        .then((response) =>
        {
            console.log(this.props.salon);
            return response.json();
        })
        .then((responseData) => {
            responseData.map(function (v) {
                v.platform = v.app ? v.app.platform : null  })
            this.setState({customers:responseData});
           //console.log(responseData);

        })
        .catch(function() {
            console.log("error");
        });
}

The .log console inside the then function will tell me this array:

(22) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0
:
{_id: "591d66f69ea5d935ed4b9ba9", shop: {…}, email:...

Array with client _id

, , ?

+4
2

API. , ._id, .

0

:

getCustomers(){

    fetch(

        DOMAIN+'/api/customers/shop/'+this.props.salon, {
            method: 'get',
            dataType: 'json',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization':'Bearer '+this.props.token
            }
        })
        .then((response) =>
        {

            return response.json();
        })
        .then((responseData) => {
            responseData.map(function (v) {
                v.platform = v.app ? v.app.platform : null  })
            this.setState({customers:responseData});
           //console.log(responseData);

        })
        .catch(function() {
            console.log("error");
        });
}

handleClick .:_id id

 handleCellClick(y,x,row){
    //this.getHistory(this.state.orders);
    this.getHistory();
    var ab= this.state.orders
    this.setState({
        open:true,
        slideIndex: 0,
        newForm:false,
        customer:{...row,_id:row._id},
        order:{...x,customer:x.customer}

    });
    this.getCustomers(row._id);

    console.log(row._id);
    console.log(x.customer);

}
0

Source: https://habr.com/ru/post/1682857/


All Articles