Error: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft

The issue is the use of an arrow function with no curly braces as the reducer, because that acts as an implicit return statement. So, you’re both mutating state.token, and returning the result of the assignment.

Per the Immer docs on returning data, there’s a couple ways to fix this:

  • Adding the void operator in front of the assignment
  • Wrapping the assignment in curly braces to make it a function body

so setToken reducer can be updated with void as

setToken: (state, action) => void(state.token = action.payload.test)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)