Redux is a library which is use to maintain state of the application at application level , it reduces complexity of managing different states of the components when app is getting comparatively larger , it provides the privilege to maintain state of different components efficiently.
Redux works on three basic principles
1) “Single source of truth” – It means that there is only one store having giant object called application state for the entire application which resides in the store.
2) State is read only – The only way to change the state is dispatching an action.
3) Changes are made with pure function ie. reducer – Dispatched action will be received by the reducer which modify the state in the store if required.
Reducer is nothing but just a pure function.which produces state out of action and whatever reducer returns will become state of the application.
Reducer called with two argument , first is current state and second is action, that dispatched before, now reducer will filter out action and produce some amount of data as a state.and that state is going to persist in the store ,in this example if the user tries to login ,dispatching and action , and that action go though all the different reducer and persist state or saving the credential to the store.
Store holds application, we can think it as an object tree, store allows to access the state via getState() and gives us current state of the application method and also allow change within the store by dispatch() method.
Redux library gives a method createStore() which takes reducer as a argument by which state of the store is going to be changed.
so basically redux is all about managing state , all we need to do is dispatching an action , it goes all the different reducer , reducer produce some amount of data as state in store