1

I am looking to build an web application utilizing React/Redux to have multiple widgets (unknown number) displayed on the screen. Widgets may share data with each other, but in most cases the data per widget will be unique.

I was considering using a data array of objects in the Redux state where each entry has a unique specifier telling us what type of data it is. Then in a high level container class I would update the data for each entry in the array as required. The actual widget components would then receive the data via props whenever it changed.

Is this approach considered good practice ?
If anyone has any recommendations, I'd love to hear.

Aerole
  • 105
  • 2
  • 10
  • As long as your `high level container class` doesn't mess with the store's data directly, but does so by dispatching actions that tell the reducer how to update the data, and it does so immutably, then you just described a very good practice react/redux app! – alechill Dec 05 '17 at 14:54
  • Since you're using Redux, it might be cleaner to let each widget component manage its own data. Unless of course each widget is just displaying the same data set in different ways. In that case, it makes more sense to let the high-level component manage the data and pass it down to the children. – T Porter Dec 05 '17 at 15:09
  • Yes I was thinking of maybe letting each widget manage its own data. The only situation would be if different widgets use the same data (not common, but can happen), and thus your dispatching the same action twice. I found redux-requests which seems to be a convenient middleware which seems to handle this issue however. – Aerole Dec 05 '17 at 16:10

0 Answers0