首页 > 解决方案 > 属性描述必须是新的 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

标签: javascriptreact-native

解决方案


从发布的代码来看,我猜这与这一行有关:

<Text style={styles.instructions}>{instructions}</Text>

指令是一个对象而不是一个字符串


推荐阅读