DEV Community

Cover image for What is State-Management and Why You Should Learn It?
Abdur Rehman Khalid
Abdur Rehman Khalid

Posted on

What is State-Management and Why You Should Learn It?

Before getting into the state-management it is important to know that what is state? If we understand the concept of state, then it will become quite easy to understand the Management of the State and How we can do that as well.

What is State?

State is something that is part of your application, such as the list of customers, a list of products coming from a database is a type of state. In a similar way, the events happening in the browser or the color or the shape or a div is also a state.
The state can be from the back-end, from the database or components of the front-end as well.

As Now we know in a simple manner that what is State, so we can move forward to discuss what is State-Management

What is State-Management?

State-Management is the implementation of a Design Pattern, with the help of this design pattern we can synchronize the state of the application throughout all components of the application. This design pattern makes the implementation of services and handling of data coming from the database very easy.

Some of the Benefits of State-Management Has Been Described Below as well

Benefits of State-Management

  1. The State of the Whole Application is present at a single place, so we do not need to access the single state or data from different places.
  2. It reduces the HTTP requests sent to the back-end for fetching and retrieval of the data.
  3. If data changes or new data is being added then and only then the request to the server will be sent.
  4. We will be doing two tasks, sending data to the server for updating the database, and also updating the overall state of the application using the RX.JS library as well.
  5. State-Management helps to centralize and made the maintenance of code very easy, also it improves the quality of code, by reducing the code size and making it more readable as well.

As Now We Know the Benefits of the State-Management, it is important to know when to implement it as well, so the next section deals with this thought.

When to Implement the State-Management?

Applying the State-Management is not so easy, it is a hard kind of work and it also takes time for implementation as well. So, it is very important to know when to implement the state-management.

  1. If the application contains a large number of components and a lot of requests are being sent to the back-end for data retrieval, then it becomes mandatory to implement the state-management, as it will boost the user experience and speed of the application to a great extent.
  2. It the redundant data is used throughout the whole application, for example, a list of customers is being used in the invoice creation and sales report generation then there is no need to fetch customers again and again from the database.

How to Implement the State-Management?

There are a lot of ways through which you can implement the State-Management in your applications. I will be talking with respect to the famous JavaScripts frameworks below.

State-Management in Angular

There are a lot of libraries for managing the state for Angular Applications, but I prefer using NGRX. I have found NGRX quite straight forward and easy to implement. The documentation is quite well explained and the instructions are provided in a very concise and clear way.

State-Management in React

It all started when React introduced the Redux Pattern, on this pattern all other frameworks started work and produced libraries for Managing the State. So the Redux is a go for React Developers to implement the State-Management in their React Applications.

State-Management in Vue

Now being flexible and easy to learn, the VUEX has played an important role, helping the developers to manage their VUE.JS applications in a very easy way.

At the end I would like to say:

State-Management is important to a great extent in large scale applications and it also makes the architecture and quality of code better than before. By managing the state, we will be able to optimize the performance in a perfect manner.

Top comments (4)

Collapse
 
xenxei46 profile image
Wisdom John ikoi

Thanks Abdur pretty short and straight forward

Collapse
 
binarygit profile image
binarygit

Hey Abdur, Thanks for the great article. Helped me loads!

Collapse
 
andresdev profile image
Andrés Márquez

Thanks Abdur. I begun with React.js a few months before and I didn't understand why we need to implement states management. Now, I understand better these concepts.

Collapse
 
abdurrkhalid333 profile image
Abdur Rehman Khalid

First of all congratulations on getting started to learn React.Js I wish you a best of luck in your journey and thank you for your comment as it has motivated me write other things for beginners as well.