-4
const [state,setState]={
    "abc": 0,
    "bce": 0,
    "sal": 0,
    "mek": [
      {

        "entityid": 0,
        "ol": 0,
        "salincomeId": 0,
        "jCK": 0,
        "description": "",
        "AMT": 0,
        "AA": 0
      }
    ]
  }

i have this object ,i am handing it with onChange Event this works fine for outer object I am not able , onChange mek the array inside the object

const handleInput=(event,name)=>{

    const value=event.target.value

    setState({
      ...State,
      [event.target.name]:value
    })

how can i put values to mek here

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Xahiid M
  • 9
  • 1

1 Answers1

-1

I guess something like this. But you need to consider that it's an array.

const {value, name} = event.target;

this.setState((state) => ({
    ...state, mek[0]: { ...state.mek[0], [name]: [value] }
}))
Andrey RF
  • 342
  • 3
  • 13
  • const {value, name} = event.target; this.setState((state) => ({ ...state, mek[0]: { ...state.mek[0], [name]: [value] } })) this way its accessing the correct variable which is 'description' but after i start writing anything it throw an error ,Cannot read property 'description' of undefined – Xahiid M Apr 21 '20 at 15:29