SetState Vs ReplaceState

Which should be used and where? Let’s see.

setState it merges current and previous state are connected. ReplaceState throws out the current state. Then it replaces with what we give. SetState is used only if you really need to remove keys. Setting it false/null is a more better way. It is possible that it could change. The object passed is used as state by replaceState. It could be used as an optimization because it is a little lighter compared to setState.

Suppose your current state is {a: 1}, and you call this.setState({b: 2}); when the state is applied, it will become {a: 1, b: 2}. If you called this.replaceState({b: 2}) your state would be {b: 2}.