Skip to content

REACT Best Practices setState

Patrick Alvin Luwum edited this page Jun 20, 2018 · 1 revision

Avoid using setState and component lifecycle hooks with Redux:

Manage the application state using redux store when it is in global state. Avoid using setState in your component when you are using state management libraries like redux. Use component state when it makes sense ie. A Button component that shows a tooltip when hovered would not use Redux.

Avoid Doing this.

image

Instead do this

image

Here we used the redux store to get state and render it in the view directly. There is no need of using setState and component lifecycle hooks again. Redux is there to do the state management job for you.