React is a JavaScript library for creating user interfaces. It has become one of the most popular libraries due to its simplicity and performance. While using React, it is very important to know about the state of React component and how to change it.

I found mutating the state can be very tricky and can possibly introduce a lot of problems. In this article, I am going to talk about the fundamental things you need to know about setState(). This includes some properties of setState() and detailed explanations about setState() in different lifecycles.

Let’s begin our journey and start with something easy.

What does setState() do?

To better understand what setState() does, let’s first take a look at what the state of a React component is.

The state allows React components to change their output over time in response to user actions, network responses, etc, without violating their…

Annie Wang

Co-op at P&C team at Hootsuite. A software engineer who loves critical thinking and likes to seek all the joyful and beautiful things in life. ╮(✧ఠ 。ఠ)╭

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store