What is Redux and Why it is Used
Normally, in apps created with front-end frameworks, state is only available within the parents and children of component that it was created in. Accessing the state in other parts of the application is somehow difficult or complex.
You can use React’s context API to access state from different parts of the app. You can also use Redux.
Why Use Redux
With Redux, you can create and manage a “global” state - a state that is used across many parts of your application. Redux helps you view and update this global state in your application in a predictable way.
You can understand when, where, why, and how the state in your application is being updated, and how your application logic will behave when those changes occur.
Its important to note that not all apps need Redux.
According to Redux official docs, Redux is more useful when:
- your app has medium to large codebase, and has multiple developers working on it
- Application state is large and required in many places in the app.
- your app state is frequently updated
- your app logic that updates the state is complex
Other Redux Libraries
The Redux package can work on its own, but its commonly used with:
React-Redux React-Redux package allows your React component to interact with the Redux store. With Redux-React package, your react app can read and update the state stored in Redux.
Redux Toolkit Redux toolkit is the recommended way of building a redux app. Having a recommended method makes it easier to write redux apps especially if you are working in a team. It also prevent common mistakes.
You may find Redux using Redux toolkit difficult to understand. When that happens, try using Redux without Redux toolkit first so that you understand what is happening.
Hi there! I am Avic Ndugu.