简体   繁体   English

未捕获的错误:对象作为 React 子项无效

[英]Uncaught error: Objects are not valid as a React child

I'm really new to react, im trying to build an app in that library, however i keep running into this error and i don't know what it does nor how to resolve it.我真的很陌生,我试图在那个库中构建一个应用程序,但是我一直遇到这个错误,我不知道它做了什么,也不知道如何解决它。 I'm just trying to pass data from a parent component to a child component, previously i was trying to do that from a fetch and from an array but now it's just basic props and still i get this error.我只是想将数据从父组件传递到子组件,以前我试图通过获取和数组来做到这一点,但现在它只是基本道具,但我仍然收到此错误。

the parent component父组件

import axios, * as others from 'axios';
import Row from 'react-bootstrap/Row';
import Cerd from "./Cerd";
import movieArray from "./MovieArray";


export function UseFetch(message){

   let number =  movieArray.length;
   console.log(number);
   let image = movieArray[0].image;
   let text = movieArray[0].title;
   let actors = movieArray[0].actors;
   const toStringer = text.toString();
console.log(toStringer);

    return(
        <div className="row-wrapper">
            <Row>    
                <Cerd title="ciao"/>
            </Row>
        </div>
        )
        
    }

the child component:子组件:

mport Card from 'react-bootstrap/card';
    
export default function Cerd(title){
    console.log(title);

    
    return(
        <div>{title}</div>
    )
    
}

Here's the error:这是错误:

1个

I already tried to change computer and search for solutions online but nothing changes, I0m not passing an array or an object in the props as it is just a simple string.我已经尝试更换计算机并在线搜索解决方案但没有任何变化,我没有在道具中传递数组或对象,因为它只是一个简单的字符串。 This is a killer error because it's not the first time that happens to me and i still haven't found what to do when it happens... can somebody help?这是一个致命的错误,因为这不是第一次发生在我身上,而且我仍然没有找到发生时该怎么做......有人可以帮忙吗?

In react component props passing, you cannot take it like taking from function.在 React 组件 props 传递中,你不能像从函数中获取一样。 You defined "title" in props of component, but you cannot take it as a variable.您在组件的道具中定义了“标题”,但不能将其作为变量。 You have to take it as shorthand.你必须把它当作速记。

// your code;
export default function Cerd(title){

// must be;
                               \/
export default function Cerd({title}){

Try ({title}) instead of (title).尝试 ({title}) 而不是 (title})。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React:Uncaught Error:对象作为React子对象无效 - React: Uncaught Error: Objects are not valid as a React child 未捕获的错误:对象作为React子对象无效 - Uncaught Error: Objects are not valid as a React child 间歇性的React Uncaught错误:对象无效作为React子级 - Intermittent React Uncaught Error: Objects are not valid as a React child 如何处理未捕获的错误:对象作为 React 子错误无效 - How to handle Uncaught Error: Objects are not valid as a React child error 如何调试此错误:未捕获(在promise中)错误:对象作为React子对象无效 - How to debug this error: Uncaught (in promise) Error: Objects are not valid as a React child 未捕获的错误:对象作为 React 子对象无效(找到:[object HTMLImageElement]) - Uncaught Error: Objects are not valid as a React child (found: [object HTMLImageElement]) 未捕获的错误:对象作为React子元素无效,但它是一个数组 - Uncaught Error: Objects are not valid as a React child but it's an array 我收到此错误“未捕获错误:对象作为 React 子项无效”,即使我使用了对象数组怎么办 - I getting this error 'Uncaught Error: Objects are not valid as a React child' even if I used Array of objects what to do 对象无效为React子错误 - Objects are not valid as a React child error 未捕获的错误:对象作为 React 子项无效。 使用反应流编辑器时 - Uncaught Error: Objects are not valid as a React child. when using react-flow-editor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM