- Published on
Using What is Already in the Redux Store
- Authors
- Name
- Yair Mark
- @yairmark
On a project I have been working on recently Redux is being used to manage shared state. One advantage of this is that if you need to add a new feature that relies on a varient of data that is already in the store you can avoid additional server calls and also avoid additional backend work (to expose that new data).
For example say I had a requirement to get all users above the age of 18. But I already have an existing call to the server to get all users which are stored in a variable called allUsers
. This means for my new requirement I can add an action that takes the existing allUsers
value from the store, filter out users above 18 const olderUsers = allUsers.filter(user => user.age >= 18)
and simply assign that new variable olderUsers
to my event store and voila I am done. No new REST endpoint is needed and no additional server call is needed.