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
  • 4,673
  • 17
  • 65
  • 138

1 Answers1

2

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
  • 270,417
  • 55
  • 406
  • 400