0

I have to send the modified data to an api which has json format as below:

{
"Customer": {
    "name": "ABC",
    "email": [email protected],
    "password": ""
},
"access": true,
"time": 2000
}

On save I want to set the respective state to api fields.

save=()=>{
    let newCustomer={
        access:this.state.access,
        time:this.state.time,
        name:      //How can i set the state values for name,email and 
                     password which is in nested form?
        email:
        password:

    }
     return axios.put('api',newCustomer)
     .then(response => {

    })
}
1
  • What’s the issue are you facing? Commented Oct 1, 2018 at 10:14

2 Answers 2

1

You can directly declare it like your json format.

let newCustomer={
  access:this.state.access,
  time:this.state.time,
  Customer: {
    name: ..., // state name from your nested form
    email: ...,  // state email from your nested form
    password: ..., // state password from your nested form
  },
}
Sign up to request clarification or add additional context in comments.

2 Comments

You might could mark this as answer to help others to fix the same problem. :D @Pooja
I have marked it as useful.Since my reputation is not more than 15 it won't be displayed publicly but the votes will be considered @Bukhari
0
        save=(Customer)=>{
            let newCustomer={
                ...Customer,
                access: this.state.access,
                time: this.state.time,
            }
            return axios.put('api', newCustomer)
            .then(response => {
                console.log(response);
            })
        }

Then newCustomer will be like Customer but access and time may be different. In backend you cann access customer name and email like you are accessing an array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.