4

An application I'm currently working on in our front end we currently use React, Redux and some singleton services (wrappers around some 3rd party libraries). We started discussing a new feature which we need to develop which involves non-changing data (as far as we can see) as it is set when the app is initialised, validated and available to the react application before our React.dom call. It is also used by some singleton services, such as a HTTP interceptor, that start in our root components constructor.

We then started discussing how we should store and use the data within our application.

We are split between storing this data using:

  1. Redux (as per app design); or
  2. a singleton service

Redux is amazing at re-rendering a component when values change and allowing intermediate states when a value is changing (I.e. a user logging in) while allowing access to that data with some additional boilerplate code. However this use case doesn't need this reloading mechanic so it seems a little overbaked whereas a singleton service seems like we don't need those benefits.

Both solutions technically work and will get the job done but what tool should we have used for that situation?

Also, if Redux is the correct one, should you ever create singleton services in React?

Elliot Smith
  • 59
  • 1
  • 5

1 Answers1

1

It's a bit late in the day, but I've been asking a similar question recently. It does seem to me that a well designed layer of singleton services (using RxJS) can (and should!) replace most of the uses of Redux I've seen.

The one time I would consider using Redux over a singleton service is to maintain a dataset that will be updated by multiple actors (typically two: the user and the server) in a manner that precludes their being a part of the same module.