immerjs / use-immer

Use immer to drive state with a React hooks
MIT License
4.04k stars 92 forks source link

alternate syntax for reducer #2

Closed xaviergonz closed 5 years ago

xaviergonz commented 5 years ago

what about something like this instead?


function reducer(draft, action, setState) {
  switch (action.type) {
    case "reset":
      setState( initialstate) ;
      break
    case "increment":
      draft.count++;
      break
    case "decrement":
      draft.count--;
      break
  }
}```
xaviergonz commented 5 years ago

and if it returns something it throws (or does nothing) return void gets old quickly

mweststrate commented 5 years ago

I think it in it's current form, it would make this approach slightly different from how normal immer producers look, making it confusing.

That being said, this proposal is quite similar to https://github.com/mweststrate/immer/issues/246, which introduces a replace api, and I think we can continue the discussion there :)