When has global state greatly helped you? (Redux/Flux/Vuex)

When I started learning Meteor, I used Session a lot, but it was rarely for actual global state. I was mostly annoyed that it was global, and usually always reset it in Template.onCreated().
When I found out I could attach a ReactiveDict to my Templates, I was very happy, as that gave me exactly what I had wanted.

Redux seems to have almost become a religion for some, and right now I’m learning Vue, which has it’s own official Vuex store. So clearly it’s very popular, but I just can’t think of many use cases where I would need it. If the data is temporary, I like to store it in the component/template, and I’m happy that it gets destroyed along with the component. And if the data is important, then I store it in a Collection, so that it’s immediately saved on the server. I’m sure they have their use cases, but for most cases global stores seem like an unnecessary middleground to me.

What problems have you encountered where Redux/etc. really helped you?

1 Like

Data binding in react can become very complex. Since you have a component tree and you pass down props, it can become very difficult to prevent unwanted render inefficiencies making the app very slow.

Redux gives you the ability to decouple the tree in react and only make components dependent on props which it actually needs, instead of passing props though a ‘middle’ component to get data from parent to child - and in the process unwanted rendering of the middle component.

To sum up - At first I thought Redux added unnecessary complexity to the code. So I wrote a complex dashboard app with without Redux, passing props where data was required. This lead to a very complex code structure where I had to pass data up (passing state mutation functions) and down again to share data between two child components. It soon became basically unscalable and slow. Optimizing was a nightmare. Then I rewrote with redux. Tree is mostly decoupled and optimizing render in broken into small chunks instead of one big mess. Much more maintainable and easier to reason and optimize now with Redux.

2 Likes