简体   繁体   English

反应来自 object TypeError 的显示数据:值 map 不是 function

[英]React display data from object TypeError: value map is not a function

Getting "TypeError: value is undefined" error when trying to render the data from the value object, when I console log value the object does show.尝试从值 object 渲染数据时出现“TypeError:值未定义”错误,当我控制台日志值 object 确实显示时。

CODE代码

import React from "react";
import { useParams } from "react-router-dom";
import {
  useDocumentData,
} from "react-firebase-hooks/firestore";
import firebase from "../firebase";

const firestore = firebase.firestore();

const Threads = () => {
  const { threadId } = useParams();
  const [value, loading, error] = useDocumentData(firestore.collection("threads").doc(threadId));
  console.log(value);
  return (
    <div>
      {value.map((thread, i) => (
        <div>
          <h1>{thread.title}</h1>
          <p>{thread.desc}</p>
        </div>
      ))}
    </div>
  );
};

export default Threads;

CONSOLE安慰

在此处输入图像描述

ERROR错误

在此处输入图像描述

The variable value is a object.变量值为 object。 Map function in JS is applicable only for arrays. JS中的Map function仅适用于arrays。 So try this.所以试试这个。

        <div>
          <h1>{value.title}</h1>
          <p>{value.desc}</p>
        </div>

   

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

相关问题 使用反应:TypeError:value.products.map 不是函数 - using react: TypeError: value.products.map is not a function 未捕获的类型错误:data.map 不是 function。 反应功能组件 - Uncaught TypeError: data.map is not a function. react functional component TypeError:data.map不是函数 - TypeError: data.map is not a function TypeError: users.map 不是 function React js - TypeError: users.map is not a function React js 对象作为 React 子级无效 - 无法在 React 中显示来自 object 的值 - Objects are not valid as a React child - Unable to display value from object in React TypeError:data.map 不是函数 Reactjs - TypeError: data.map is not a function Reactjs 我的文件在第一行失败,从“ react”导入React,出现TypeError:Object(…)不是一个函数 - My file is failing right at the very first line, import React from “react”, with a TypeError: Object(…) is not a function 未捕获的类型错误:(中间值)(中间值)(中间值)。map 不是 function - Uncaught TypeError: (intermediate value)(intermediate value)(intermediate value).map is not a function TypeError - indexOf 不是 function (React Data Search with MySQL) - TypeError - indexOf is not a function (React Data Search with MySQL) Uncaught TypeError: Iterator value undefined is not an entry object”添加过滤器到 map - Uncaught TypeError: Iterator value undefined is not an entry object" Adding filter to map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM