How Redux Works ?
Introduction
We know what is redux and as we know it is an alternative to react context hook . Redux is an replacement for react context and cover many potential disadvantages when using cross component and app wide state across multiple components . Let's explore core redux concepts and how we use redux in our react applications with the flow diagrams . So it better understand to you and the concept easily get into your projects.
Redux , stores the state in the centralized location where it can be used globally over the web across multiple components. So we should first be discussing about that peace of content.
1) Central data store generally keep all the state or updates of state which later notifies the component which state has changed . Central Data Store is the location where all the mutation or updates of state kept which later be used in the component.
2) After setup the central data store for managing the state , how the store notify the component if some state has changed ? . To access state from the store , component need to subscribe the state and by subscribing to the store , component can have access to the state of the store and store will notify to the component if some state has changed.
But component generally mutates the state , example on button click etc. Here the component cannot directly mutate the state and can only read the state but cannot write directly . It is unidirectional and so how we update the state in the store , if we cannot change through the component directly?
You might be wondered , generally they are the components who changes the state with some user input . In redux , components triggers or dispatch some actions which notify the reducer function at what action the state should update , on the basis of description of action the state updates .
Thank you for reading :)
Comments
Post a Comment