【问题标题】:How do I debug "Objects are not valid as a React child" react native error如何调试“对象作为 React 子项无效”反应本机错误
【发布时间】:2017-05-11 05:53:20
【问题描述】:

对象作为 React 子对象无效(找到:带有键 {style, title} 的对象)。如果您打算渲染一组子项,请改用数组或使用 React 附加组件中的 createFragment(object) 包装对象。检查View的渲染方法。

我不知道如何处理我粘贴的跟踪,因为它根本不在我的代码中。任何想法将不胜感激!谢谢。

Trace on simulator

index.ios.js

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Navigator
} from 'react-native';

import Product from './product.js';
import Services from './services.js';
import ProductsList from './productslist.js';
import AddProduct from './addProduct.js';
import {StackNavigator} from 'react-navigation';

const routes = [
  {
    title : 'Services',
    renderFunc : (navigator) => <Services navigator={navigator} />
  },
  {
    title : 'Marketplace',
    renderFunc : (navigator) => <ProductsList navigator={navigator}/>
  }
];

const stackNavigatorRoutes = {
  Services : {
    screen : Services,
  },
  ProductsList : {
    screen : ProductsList
  },
  Product : {
    screen : Product
  },
  AddProduct : {
    screen : AddProduct
  }
};

const AppNavigator = StackNavigator({
  ...stackNavigatorRoutes,
},
{
    initialRouteName : 'Services',
    navigationOptions : {
        header : {
          style : {
            height : 60,
            backgroundColor : 'cadetblue'
          },
          title : 'ResiShare'
        }
    }
});

class Rs extends Component {
  render() {
    return (
        <AppNavigator />
        // <ProductsList />
        // <AddProduct />
      );
  }
}

【问题讨论】:

  • 我认为您应该提供部分代码,这对错误负责。
  • 将入口点添加到我的应用程序中,即使跟踪根本没有引用它。

标签: react-native


【解决方案1】:

我的问题的主要目的是找出调试类似这样的东西,其中跟踪不显示任何我的代码

答案是用可行的东西替换 index.ios.js 中的入口点,然后慢慢添加回组件。

在这种特殊情况下,这种 fubar-ing 的原因是 react-navigation (https://github.com/react-community/react-navigation/issues/1413) 的重大变化,我没有意识到我已经接受了(我肯定已经安装了 npm)。

【讨论】:

    猜你喜欢
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    相关资源
    最近更新 更多