DEV Community

Discussion on: Managing State in React: Redux or not Redux?

Collapse
 
borislemke profile image
Boris Lemke • Edited

I hate the reducer form in redux. switch (action.type)... just looks ugly and doesn't provide autocompletion / type-checking info in your IDE. I prefer to use mobx / rxjs.

Instead of:

switch (action.type):
  case LOAD_TALKS:
    ...
  case LOAD_TALKS_ERROR:
    ...

it would be:

class SomeStateManager {
  state

  loading

  error

  loadTalks(...params) {
    // do something with state
    loading = true
  }

  loadTalksError(...params) {
    // do something with state
    loading = false
    error = params.error
  }
}

Especially when using TypeScript, this would make much more sense and give you the benefit of type-checking.