0
case 'ADD_CHAT_MESSAGE':
    const index = state.tasks.findIndex(elm => elm.userid === action.taskid)
    const task = state.tasks
    return update(
      state, { tasks: { index: { $set: action.task } } })

I would like to use index inside update function but my IDE alerting me that index is declared nut never used.

infodev
  • 3,933
  • 13
  • 50
  • 115

1 Answers1

1

Since index is dynamic, you must use [] with it, otherwise it will just be setting the index key

case 'ADD_CHAT_MESSAGE':
    const index = state.tasks.findIndex(elm => elm.userid === action.taskid)
    const task = state.tasks
    return update(
      state, { tasks: { [index]: { $set: action.task } } })
Shubham Khatri
  • 246,420
  • 52
  • 367
  • 373