react+redux使用static mapStoreToProps
生活随笔
收集整理的這篇文章主要介紹了
react+redux使用static mapStoreToProps
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
以下是redux官網上使用的connect用法:
class Container extends React.Component{... } const mapStateToProps = (state, ownProps) => {... }const mapDispatchToProps = (dispatch, ownProps) => {... }export default connect(mapStateToProps,mapDispatchToProps )(Container)我就不太喜歡這種表達方法,我的目標是將map方法放進Container中作為靜態方法,直接使用Container就是connect后的組件。經過我的多番嘗試,最終使用Decorator實現:
function connection(target){return connect(target.mapStoreToProps , target.mapDispatchToProps)(target); }@connection class Container extends React.Component{...static mapStateToProps(state , ownProps){...}static mapDispatchToProps (state , ownProps){...} }export default Container ;經過Decorator修飾的Container就可以使用redux中的數據了。
轉載于:https://www.cnblogs.com/bykp/p/6607941.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的react+redux使用static mapStoreToProps的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 香菇在什么地方有毒样视频?
- 下一篇: 分书 回溯搜索