簡體   English   中英

如何在反應組件中使用 redux 與 withNavigation 一起

[英]How to use redux in react component with withNavigation together

我正在嘗試將一些組件(標題)連接到我的 redux 商店。 我已經成功地從其他組件連接了商店並且它工作正常,我認為我在連接商店時遇到了問題,因為在組件中使用了 withNavigation。 關於為什么我的組件沒有連接到商店的任何想法?

我的減速機

 import articles from '../../constants/articles' const intialState = { orderList: articles, name: "Please work" }; const orderReducer = (state = intialState, action) => { switch (action.type) {.... default: return state; } }; export default orderReducer;

我的 Header 組件沒有連接

 import React from 'react'; import { withNavigation } from '@react-navigation/compat'; ... import {connect} from 'react-redux'.... class Header extends React.Component{... const { back, title, white, transparent, bgColor, iconColor, titleColor, navigation, ...props } = this.props; ... return ( <Block style={headerStyles}> <Block> //************the warn that displayed is "undeinded"**************** {console.warn(this.props.name)}..... </Block> ); } const styles = StyleSheet.create({... }); const mapStateToProps = state =>{ return{ name: state.name } } export default withNavigation(connect(mapStateToProps)(Header))

我了解錯誤是什么,我嘗試使用連接商店

 const mapStateToProps = state =>{ return{ name: state.name } }

但我不知道我應該像這樣添加 orderReducer:

 const mapStateToProps = state =>{ return{ name: state.orderReducer.name } }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM