sgoran
sgoran

Reputation: 976

How to filter redux store data on several places

If I have redux store with list of cars.

And I use that list to populate several components like dropdown and for example table (which can be filtered).

When I filter table, my dropdown will be filtered to, beside it's on other page, they share same store.

And if I clone that part of data in store I would loose option to add/edit on all places.

What are best practices for this kind of cases? And examples maybe?

Upvotes: 1

Views: 1573

Answers (2)

sgoran
sgoran

Reputation: 976

As I can see this article explains this question well, didn't see it earlier:

http://redux.js.org/docs/recipes/ComputingDerivedData.html

So this could be correct way to filter or do anything else without polluting the store data.

Upvotes: 0

Radu Nemerenco
Radu Nemerenco

Reputation: 676

You should avoid editing the store data from inside the components. When you filter your list in the component - create a new, cloned instance of the list - to be sure you don't change anything in the store.

When you want to change anything in the store - use actions.

You should keep the Store data as readonly in Components.

I found a good article on this topic https://hackernoon.com/redux-step-by-step-a-simple-and-robust-workflow-for-real-life-apps-1fdf7df46092

Upvotes: 2

Related Questions