简体   繁体   English

我正在尝试从 mongodb 服务器呈现数据以响应应用程序。 它不工作

[英]I am trying to render data from mongodb server to react app. And it's not working

This is the console log error这是控制台日志错误

Uncaught Error: Objects are not valid as a React child (found: object with keys {_id, inputText, __v}). If you meant to render a collection of children, use an array instead.
at throwOnInvalidObjectType (react-dom.development.js:14887:1)
at reconcileChildFibers (react-dom.development.js:15828:1)
at reconcileChildren (react-dom.development.js:19167:1)
at updateHostComponent (react-dom.development.js:19924:1)
at beginWork (react-dom.development.js:21618:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
at invokeGuardedCallback (react-dom.development.js:4277:1)
at beginWork$1 (react-dom.development.js:27451:1)
at performUnitOfWork (react-dom.development.js:26557:1)

I am being able to save my input to the server but am getting error while trying to fetch it.我能够将输入保存到服务器,但在尝试获取它时出错。 Here's the component which is supposed to return the list.这是应该返回列表的组件。

import React, { useState, useEffect } from "react";
import ToDoItem from "./ToDoItem";
import InputArea from "./InputArea";
import "bootstrap/dist/css/bootstrap.min.css";
import axios from "axios";

const ToDoList = () => {
const [x, setX] = useState([]);
const xList = () => {
return x.map((y,index) => {
  return <ToDoItem key={index} text={y} />;
});
};
useEffect(() => {
axios
  .get("http://localhost:5000/")
  .then((res) => {
    setX(res.data);
  })
  .catch((err) => console.log(err));
  }, []);

 return (
 <div className="container">
  <div className="heading">
    <h1>To-Do List</h1>
  </div>
  <InputArea />
  <div>{xList()}</div>
 </div>
 );
 };

 export default ToDoList;

That specific error usually occurs when you are trying to print out an entire object instead of lets say the properties from each object.当您尝试打印整个 object 而不是每个 object 的属性时,通常会发生该特定错误。

Can you console.log the list and let us know what properties you have for each object?您能否控制台记录该列表并让我们知道您对每个 object 有哪些属性?

暂无
暂无

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

相关问题 我正在尝试在我的 react redux 应用程序中使用 map。 但使用useDispatch后,控制台显示错误 - I am trying to use map in my react redux app. but after using useDispatch, the console is showing error 在我的应用程序中反应错误。 试图传播嵌套对象以更新数据,但我相信我说错了,因此进行了两次 useState 调用 - React bug in my app. Trying to spread nested objects to update the data but I believe I am calling it wrong thus making two useState calls 我正在尝试运行此反应本机屏幕,它会为我获取数据。 当我从主屏幕单击文本时,它会运行。 但它不工作 - I am trying to run this react native screen where it fetches data for me. This gets run when i click the text from a home screen. But it's not working 我正在尝试将 mongodb 服务器与节点连接 - I am trying to connect mongodb server with node 我在将找到的现有 React 组件集成到我的应用程序中时遇到问题。 “尝试导入错误:” - I am having an issue with integrating an existing react component I found, into my app. "Attempted import error:" 我正在尝试在 React 中创建一个盒子,但它不起作用 - I am trying to create a box in React, and it is not working JavaScript 天气应用程序。 当您单击它时,我想将温度从 C 更改为 F。 它不工作 - JavaScript Weather App. I want to change the temp from C to F when you click on it. It's not working 试图为我的应用程序提供过滤功能。 渲染错误:重新渲染太多。 React 限制渲染次数 - Trying to come out with a filter function for my app. Render Error: Too many re-renders. React limits the number of renders 尝试在页面 REACT 上呈现数据库中的数据 - Trying to render data on from database on page REACT URL 被阻止(Access-Control-Allow-Origin - Missing Header),而我正在尝试从 Bluehost 获取数据以响应网站应用程序 - URL blocked ( Access-Control-Allow-Origin - Missing Header) while I am trying to get the data from Bluehost to react website app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM