亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復 TypeError:undefined 不是對象(評估“state.routes”)

如何修復 TypeError:undefined 不是對象(評估“state.routes”)

青春有我 2021-11-18 20:54:07
我正在關注 react 導航文檔,react-navigation-redux-helpers 的文檔,但總是向我拋出這個錯誤。此外,如果我刪除了persistGate,錯誤會得到修復,但我需要保留一些數據,所以這不應該是一個選項這是我的 store.jsimport { createStore, applyMiddleware } from 'redux';import { persistStore, persistReducer } from 'redux-persist';import { AsyncStorage } from 'react-native';import { createReactNavigationReduxMiddleware } from 'react-navigation-redux-helpers';import Reducer from './reducers/index';const persistConfig = {    key: 'root',    storage: AsyncStorage,    blackList: [],};const AppReducer = persistReducer(persistConfig, Reducer);const middleware = createReactNavigationReduxMiddleware(    (state) => state.navigation,);export const store = createStore(AppReducer, applyMiddleware(middleware));export const persistor = persistStore(store);這是我的 app-with-state.jsimport AppNavigator from './AppNavigator';const AppNavigatorWithState = createReduxContainer(AppNavigator);class ReduxNavigation extends React.Component {    render() {        const { state, dispatch } = this.props;        return <AppNavigatorWithState navigation={state} dispatch={dispatch} />;    }}const mapStateToProps = (state) => ({    state: state.navigation,});export default connect(mapStateToProps)(ReduxNavigation);這是我的 AppNavigator.jsconst Main = createStackNavigator(    {        Home: Home,        Movie: Movie,        Category: Category,    },    {        defaultNavigationOptions: {            header: Header,        },    },);const TabNavigator = createBottomTabNavigator({        Home: {            screen: Main,            navigationOptions: {                tabBarIcon: <Icon icon='??' />,            },        },        About: { screen: About },        Lucky: { screen: Lucky },        Profile: { screen: Profile },    },    {        tabBarOptions: {           activeTintColor: 'white',           activeBackgroundColor: '#65a721',        },    },);//const App = createAppContainer(TabNavigator);export default TabNavigator;
查看完整描述

2 回答

?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

我知道為時已晚,但它應該可以幫助其他人:))


在你的 mystore.js 中


const middleware = createReactNavigationReduxMiddleware(

    (state) => state.navigation,

)

應該是這樣的:


const middleware = createReactNavigationReduxMiddleware(

    (state) => state.router,

)


查看完整回答
反對 回復 2021-11-18
?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

我也遇到了這個錯誤,我沒有找到任何線索,然后卡住了。經過幾個小時的調試,這是因為我犯了愚蠢的錯誤。
這是我的錯誤案例

const customContent = ({props}) => { }

實際上,props不需要{}。只需調用(props)like 即可修復錯誤。
這是正確的案例

const customContent = (props) => { }

{}打電話時請不要加props。
希望它對像我這樣出錯的人有所幫助。


查看完整回答
反對 回復 2021-11-18
  • 2 回答
  • 0 關注
  • 313 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號