JavaScript Updates nested value in React State update nested value javascript,mongodb update nested value,jq update

I am using React/Redux for my web-app and I have the Description Class where user can edit description. Props description and propertyTypes are coming from AJAX calls.

import React, { PropTypes } from 'react';

const defaultDescription = {
  about_you: '',
  benefits: '',
  description: '',
  headline: '',
  no_of_guests: 0,
  property_name: '',
  property_type: {
    id: 1,
    name: 'Apartment',
  },
};
class Description extends React.Component {
  static propTypes = {
    description: PropTypes.object,
    propertyTypes: PropTypes.array,
  };
  constructor(props) {
    super(props);
    this.state = {
      description: defaultDescription,
    };
    this.handleInputChange = this.handleInputChange.bind(this);
    this.propertyTypeChanged = this.propertyTypeChanged.bind(this);
    this.updateDescription = this.updateDescription.bind(this);
  }
  // componentWillMount() {
  //   if (!this.props.description) {
  //     this.setState({
  //       description: defaultDescription,
  //     });
  //   }
  // }
  componentWillReceiveProps(nextProps) {
    if (nextProps && nextProps.description && nextProps.propertyTypes) {
      const newDescription = nextProps.description.description ? merge(defaultDescription, nextProps.description) : merge(nextProps.description, defaultDescription);
      this.setState({
        description: newDescription,
      });
    }
  }
  handleInputChange(event) {
    const target = event.target;
    const value = target.type === 'checkbox' ? target.checked : target.value;
    const name = target.name;
    this.setState({
      description[name]: value // <---- I want to update my state here
    });
  }
  updateDescription(event) {
    event.preventDefault();
    console.log(this.state);
  }
  render() {
    
    return (
      <form name="descriptionForm" onSubmit={this.updateDescription}>
        
        <input name="no_of_guests" value={this.state.description.no_of_guests} onChange={this.handleInputChange} /><br />
        <input name="property_name" value={this.state.description.property_name} floatingLabelText="Property Name" onChange={this.handleInputChange} /><br />
        <input name="headline" value={this.state.description.headline} floatingLabelText="Headline" onChange={this.handleInputChange} /><br />
        <input name="summary" value={this.state.description.summary} floatingLabelText="Summary" onChange={this.handleInputChange} /><br />
        <input name="description" value={this.state.description.description} floatingLabelText="Description" onChange={this.handleInputChange} /><br />
        <input name="about_you" value={this.state.description.about_you} floatingLabelText="About You" onChange={this.handleInputChange} /><br />
        <input name="why" value={this.state.description.why} floatingLabelText="Why ?" onChange={this.handleInputChange} /><br />
        <input name="benefits" value={this.state.description.benefits} floatingLabelText="Benefits" onChange={this.handleInputChange} /><br />
        <button value="Save" type="submit" />
      </form>
    );
  }
}
export default Description;
Answer:1

This is how I would update in your case

const newState = {...this.state.description};
newState[name] = value;
this.setState({
  description: newState,
});

Input elements should not switch from controlled to uncontrolled (or vice versa) [[https://facebook.github.io/react/docs/forms.html#controlled-components]]

Answer:2

I know, the title isn't really specific, but I have a problem with DatePicker. I try to disable the national days, weekend and 48 hours after today. For the moment I did this : Hide today + 48hours, ...

I know, the title isn't really specific, but I have a problem with DatePicker. I try to disable the national days, weekend and 48 hours after today. For the moment I did this : Hide today + 48hours, ...

  1. jquery datepicker disable national holidays

I have written this script that shows a div when a checkbox is ticked: <cfinput type="Checkbox" name="Agency" value="Agency" id="Agency">Agency Team<br> <div id="agcyTeam" style="...

I have written this script that shows a div when a checkbox is ticked: <cfinput type="Checkbox" name="Agency" value="Agency" id="Agency">Agency Team<br> <div id="agcyTeam" style="...

For my scatter chart in highcharts I would like different series to have different marker radius. Is this possible? "plotOptions": {"series": {"marker": {"enabled": true ...

For my scatter chart in highcharts I would like different series to have different marker radius. Is this possible? "plotOptions": {"series": {"marker": {"enabled": true ...

  1. matplotlib different marker sizes
  2. matlab different marker sizes

I am trying to serve a file manually for a specific URL. When I user the res.sendFile function I get the following error in my logs. Object [object Object] has no method 'sendFile' Express ...

I am trying to serve a file manually for a specific URL. When I user the res.sendFile function I get the following error in my logs. Object [object Object] has no method 'sendFile' Express ...

  1. serve files from s3
  2. serve files over http
  3. serve file nodejs
  4. serve file express
  5. serve files flask
  6. serve file golang
  7. serve files via http
  8. serve files from nginx
  9. serve files from github
  10. serve files
  11. serve file django
  12. serve file python
  13. serve files using nginx
  14. serve files from directory flask
  15. serve files with node js