Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux #subscribe vs. #mapStateToProps

What is the purpose of using subscribe in code like store.subscribe(render)? Doesn't using mapStateToProps and connect already cause the connected component to re-render each time the store's state changes?

like image 217
stackjlei Avatar asked Dec 02 '22 13:12

stackjlei


1 Answers

Quoting the Redux.js page:

Technically you could write the container components by hand using store.subscribe(). We don't advise you to do this because React Redux makes many performance optimizations that are hard to do by hand. For this reason, rather than write container components, we will generate them using the connect() function provided by React Redux,

If you're already using react with redux, you might as well use their package, since it is already optimized.

Also referencing a previous answer: https://stackoverflow.com/a/36214059/3938413

like image 56
Sean Kwon Avatar answered Dec 10 '22 12:12

Sean Kwon