![](/img/trans.png)
[英]JavaScript(React)- Uncaught TypeError: Cannot read properties of undefined (reading 'style')
[英]Router.js:135 Uncaught TypeError: Cannot read properties of undefined (reading 'style') in React Native
我是 React Native 的新手。 我正在嘗試使用“react-native-router-flux”中的路由器。 但我得到了這個錯誤:
Router.js:135 Uncaught TypeError: Cannot read properties of undefined (reading 'style')
at Module../node_modules/react-native-router-flux/src/Router.js (Router.js:135)
at __webpack_require__ (bootstrap:789)
at fn (bootstrap:100)
at Module../node_modules/react-native-router-flux/src/index.js (index.js:1)
at __webpack_require__ (bootstrap:789)
我的 App.js:
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { Router, Scene } from 'react-native-router-flux';
export default function App() {
return (
<View style={styles.container}>
<Router>
<Scene key="root">
<Scene key="Home"
component={Home}
title="Home"
initial
/>
<Scene
key="Forgotpassword"
component={Forgotpassword}
title="Forgotpassword"
/>
</Scene>
</Router>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
}
});
我的 package.json:
"dependencies": {
"@react-navigation/native": "^6.0.10",
"@react-navigation/native-stack": "^6.6.2",
"expo": "~45.0.0",
"expo-status-bar": "~1.3.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-paper": "^4.12.1",
"react-native-router-flux": "^4.3.1",
"react-native-safe-area-context": "^4.2.4",
"react-native-screens": "~3.11.1",
"react-native-web": "0.17.7"
},
編輯:早些時候我忘記在我的問題中添加樣式。 現在我添加了我的問題。 給您帶來的不便深表歉意。
您為您的“視圖”提供了“styles.container”的樣式,但我在您的代碼中看不到您定義“樣式”的任何地方。 您可以使用以下代碼將自定義樣式添加到您的視圖中:
const styles = Stylesheet.create({
// Write the styles here similar to CSS but in camelcase
})
請記住從模塊中的 react-native 導入樣式表。 如果您已經在代碼中定義了樣式表。 請在您的問題中包括這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.