0
    constructor(props) {
        super(props)

        this.state = {
            isEdit: false,
            currentProduct : {
                sku: '',
                productName: '',
                description: '',
                duration: '',
            },
        }       
    }    

handleChange = (e) => {
            this.setState({
              currentProduct: {
               ...this.state.currentProduct,
               [e.target.name]: e.target.value
              }
          })
       }

    clickHandle = (e) => {
        e.preventDefault()
        const currentProduct = {...this.state.currentProduct}
        currentProduct.id = this.props.match.params.id

        this.props.updateProduct(currentProduct)
        this.props.history.push('/')
    }

When updating field it updates the values but when i goes again to update single value it update only that and removes the other don't know why

1
  • Can you please share a demo? Commented Dec 30, 2019 at 11:10

2 Answers 2

2
handleChange = (e) => {
        this.setState({
           ...this.state.currentProduct,
           [e.target.name]: e.target.value
      })
   }
Sign up to request clarification or add additional context in comments.

1 Comment

Not agree did you see constructor ?
0

you are not destructuring entire state first. so do ...state. otherwise isEdit field will be lost.

  handleChange = e => {
    this.setState({
      ...this.state,
      currentProduct: {
        ...this.state.currentProduct,
        [e.target.name]: e.target.value
      }
    });
  };

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.