React Native Expo:TypeError:未定义不是对象(评估'Component.router.getStateForAction')

时间:2020-05-06 08:23:49

标签: javascript react-native expo typeerror native

我正在尝试将i18next与expo一起使用。 我有这样的i18n索引:

import i18n from "i18next"
import { initReactI18next } from "react-i18next"
import locale from "react-native-locale-detector"
import { AsyncStorage } from "react-native"

import fr from './fr.json'
import en from './en.json'

const STORAGE_KEY = '@APP:languageCode'

const languageDetector = {
    init: Function.prototype,
    type: 'languageDetector',
    async: true,
    detect: async (callback) => {
        const savedDataJSON = await AsyncStorage.getItem(STORAGE_KEY)
        const lng = savedDataJSON ? savedDataJSON : null
        const selectedLanguage = lng || locale
        console.log('detected ' + selectedLanguage)
        callback(selectedLanguage)
    }
}

i18n.use(languageDetector).use(initReactI18next).init({
    fallbackLng: 'en',
    resources: [en, fr],
    ns: ['common'],
    defaultNS: 'common',
    debug: true,
    interpolation: {
        escapeValue: false
    }
})

export default i18n

在我的App.js中:

import Container from "./Navigation/index"
// (container like that)
// const Container = createSwitchNavigator(
//     {
//         MainScreen: MainStack,
//         LoginScreen: LoginStack,
//         SplashScreen: SplashStack
//     },
//     {
//         initialRouteName: 'SplashScreen'
//     }
// )

class WrappedStack extends React.Component {
    render() {
        const t = this.props
        return <Container screenProps={{ t }}/>
    }
}

const ReloadAppOnLanguageChange = withTranslation('common', {
    bindI18N: 'languageChanger',
    bingStore: false
}) (createAppContainer(<WrappedStack />))

export default class App extends React.Component {

    render() {
        const noteAppStore = getStore()
        const noteAppPersistor = getPersistor()

        return (
            <MenuProvider>
                <Provider store={noteAppStore}>
                    <PersistGate persistor={noteAppPersistor}>
                        <PaperProvider theme={theme}>
                            <ReloadAppOnLanguageChange />
                        </PaperProvider>
                    </PersistGate>
                </Provider>
            </MenuProvider>
        )
    }
}

我正在使用: “ i18next”:“ ^ 19.4.4”, “ i18next-react-native-language-detector”:“ ^ 1.0.2”, “ react-i18next”:“ ^ 11.4.0”, “ react-native-locale-detector”:“ ^ 1.0.1”, “反应导航”:“ ^ 4.3.8”

运行博览会应用程序时,出现以下错误: TypeError: undefined is not an object (evaluation 'Component.router.getStateForAction') 我创建的包装程序有误吗? 感谢您的帮助!

0 个答案:

没有答案