javascript - 属性描述必须是新的 react-native 应用程序上的对象红屏错误
问题描述
我已经初始化了一个新的 react-native 应用程序,但即使没有对代码进行任何更改,我也会收到以下红屏错误。
Java 版本 - 8 节点 - 10.15.3 react-native - 0.57.3
由于在较新版本中遇到许多错误,我已使用较低版本的 react-native 进行了初始化。我是反应原生的新手。请帮忙。
应用程序.js 文件。
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
export default class App extends Component{
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
<Text style={styles.instructions}>{instructions}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
index.js
/** @format */
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
包.json
{
"name": "GoSurf",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.0-alpha.8af6728",
"react-native": "0.57.3"
},
"devDependencies": {
"babel-jest": "24.8.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.55.0",
"react-test-renderer": "16.6.0-alpha.8af6728"
},
"jest": {
"preset": "react-native"
}
}
显示错误:-
https://drive.google.com/file/d/1-erzk1O-mZy6q-EuFBjE3qjhPgqmaMNA/view?usp=sharing
解决方案
从发布的代码来看,我猜这与这一行有关:
<Text style={styles.instructions}>{instructions}</Text>
指令是一个对象而不是一个字符串
推荐阅读
- css - 是否可以在样式组件中使用样式系统的断点?
- android - 预览自定义视图中的 Android ResourceNotFoundException
- ibm-infosphere - 在 IBM MDM 中生成唯一的产品 ID
- php - 在 PDO MySQL SELECT 中使用 TRIM() 时出现语法错误
- excel - Excel公式:根据标题从公式中排除某些列
- r - Psych::Mediate 中的错误:找不到对象
- xcode - 使用 Xcode 开发的 iOS 应用程序嵌入 PowerBI 报告
- ssl - Firefox 可以找到证书,但 curl 不能(通过 ssh 隧道传输 https 时)
- html - HTML div元素中的反转顺序
- sql - 如何限制汇总组合