JavaScript setState for nested objects setstate nested objects react,how to setstate nested object

I have a nested object as a state and I have a form in a component. I was thinking of updating the state every time the user enter something in the form and to avoid creating many functions for each input I was thinking of creating a single function using switch.

  1. Is creating a single function with switch a good idea?
  2. How can I update a single nested element of the object?

I have tried with the following code but it doesn't work:

class App extends Component {
  constructor(props) {
      super(props)
      this.state = {
        minutes: null,
        interests: {
          business: false,
          code: false,
          design: false
        },
        errors: []
      }
  }

  updatePreferences = (preferenceName, enteredValue) => {
    switch (preferenceName) {
      case preferenceName === "minutes":
        this.setState({minutes: enteredValue})
        return
      case preferenceName === "business":
        this.setState({interests.business: !this.state.interests.business})
        return
      case default:
        return
    }

  }
}
Answer:1

I've been trying to get tags working with Jquery Datatables for about 1 week now with no luck! I've gone through stackoverflow and have not found the help i'm looking for. This post here was ...

I've been trying to get tags working with Jquery Datatables for about 1 week now with no luck! I've gone through stackoverflow and have not found the help i'm looking for. This post here was ...

  1. datatables search tags

I am using Javascript ES6 classes. I have created a Player class as below: class Player { constructor() { ..... ..... } changeShipDirection(shipName, direction) { let redraw = ...

I am using Javascript ES6 classes. I have created a Player class as below: class Player { constructor() { ..... ..... } changeShipDirection(shipName, direction) { let redraw = ...

  1. javascript calling method
  2. javascript calling method from constructor
  3. javascript calling method within object
  4. javascript calling method name
  5. javascript call method by string
  6. javascript call method from another file
  7. javascript call method dynamically
  8. javascript call method inside class
  9. javascript call method every 5 seconds
  10. javascript call method after delay
  11. javascript call method from another class
  12. javascript call method without parentheses
  13. javascript call method by string name
  14. javascript call method in class
  15. javascript call method in same class
  16. javascript call method of parent class
  17. javascript call method asynchronously
  18. javascript call method if not null
  19. javascript call method by variable
  20. javascript call method on object

I have a simple application in angular 2. I want to display data in a paginated table. I found this example very nice and I would like to use in my app. Thehtml of the example is in home.component....

I have a simple application in angular 2. I want to display data in a paginated table. I found this example very nice and I would like to use in my app. Thehtml of the example is in home.component....

  1. include data table in angular

NewBie for d3.js. I try to remove xAxis, based on the method s.selectAll("g").remove(xAxis); but it does not work. Not sure if it is the correct way to remove xAxis? Thank you in advance. 1....

NewBie for d3.js. I try to remove xAxis, based on the method s.selectAll("g").remove(xAxis); but it does not work. Not sure if it is the correct way to remove xAxis? Thank you in advance. 1....

  1. remove element from list python
  2. remove element from array javascript
  3. remove element from array java
  4. remove element from vector c++
  5. remove element javascript
  6. remove element from array python
  7. remove element from dictionary python
  8. remove element from set python
  9. remove element jquery
  10. remove element from array js
  11. remove element from arraylist java
  12. remove element from dom
  13. remove element from numpy array
  14. remove element from list python by index
  15. remove element from array c++
  16. remove element from array php
  17. remove element from array matlab
  18. remove element from list r
  19. remove element from string python
  20. remove element from array ruby