score:1

Accepted answer
const [message, setMessage] = useState({ 
  Features: { Active: false },
  General: { FileTimeout: 0, ZipDepth: 0 }
});

const handleInput=e=>{
  const { name, value } = e.currentTarget;

  setMessage(message => {
    switch(name) {
      case 'active':
        if (value === 'on') {
          return {
            ...message, // shallow copy of state
            Features: {
              ...message.Features, // shallow copy nested state
              Active: true,
            },
          };
        } else {
          // ? return some new state
        }

      case 'timeout':
        return {
          ...message, // shallow copy of state
          General: {
            ...message.General, // shallow copy nested state
            ZipDepth: 5,
          },
        };

      case 'zipdepth':
        return {
          ...message, // shallow copy of state
          General: {
            ...message.General, // shallow copy nested state
            FileTimeout: 7,
          },
        };

      default:
        return message; // no update, return current state
    };
  });
}

score:1

const [message, setMessage] = useState({ 
      Features: {Active:false},
      General: {FileTimeout:0,ZipDepth:0}
  });

const handleInput=e=>{
    const name=e.currentTarget.name;
    const value=e.currentTarget.value;

    var temp = {...message}


    if(name == 'active'){
     if(value==='on'){
      temp.Features.Active=true;
     }
     else{}
    } 
    else if(name == 'timeout'){
       temp.General.ZipDepth= 5;
    } 
    else if(name == 'zipdepth'){
     temp.General.FileTimeout= 7;
    }

    setMessage({...temp})  // You need to call setMessage function in order to update the state.
  }


Related Query

More Query from same tag