Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React数据不是';不显示_Reactjs_Axios_Use State - Fatal编程技术网

Reactjs React数据不是';不显示

Reactjs React数据不是';不显示,reactjs,axios,use-state,Reactjs,Axios,Use State,我试图显示存储在国家/地区列表中的这些数据,但是,这导致我的表中没有任何内容。问题很可能是由于表格没有正确重新排序造成的,我尝试在第14行使用useffect打印列表的长度,但得到了正确的结果。任何暗示都将不胜感激 import React, { useState, useEffect } from "react"; import getData from "../Hooks/getData"; import Table from "react-bootstrap/Table"; const

我试图显示存储在
国家/地区列表中的这些数据,但是,这导致我的表中没有任何内容。问题很可能是由于表格没有正确重新排序造成的,我尝试在第14行使用
useffect
打印列表的长度,但得到了正确的结果。任何暗示都将不胜感激

import React, { useState, useEffect } from "react";
import getData from "../Hooks/getData";
import Table from "react-bootstrap/Table";

const Lists = () => {
  const [countries, setCountries] = useState([]);

  if (countries.length === 0) {
    getData().then((data) => {
      setCountries(data.data.Countries);
    });
  }

  useEffect(() => {
    console.log(countries.length);
  });

  const getInfo = () => {
    countries.map((country) => {
      return (
        <tr>
          <td>{country.Country}</td>
          <td>{country.NewConfirmed}</td>
          <td>{country.TotalConfirmed}</td>
        </tr>
      );
    });
  };

  return (
    <Table striped bordered hover>
      <thead>
        <tr>
          <th>Country Name</th>
          <th>New Confirmed</th>
          <th>Total Confirmed</th>
        </tr>
      </thead>
      <tbody>{getInfo()}</tbody>
    </Table>
  );
};

export default Lists;

import React,{useState,useffect}来自“React”;
从“./Hooks/getData”导入getData;
从“反应引导/表格”导入表格;
常量列表=()=>{
const[countries,setCountries]=useState([]);
如果(countries.length==0){
getData()。然后((数据)=>{
setCountries(data.data.Countries);
});
}
useffect(()=>{
控制台.日志(国家/地区.长度);
});
const getInfo=()=>{
国家地图((国家)=>{
返回(
{country.country}
{country.newconfirm}
{国家/地区}
);
});
};
返回(
国名
新确认
确认总数
{getInfo()}
);
};
导出默认列表;

您的
getInfo
不会返回任何内容

通过不在函数体周围使用
{}
来使用隐式返回,或者显式使用
return
语句

 const getInfo = () => countries.map((country) => {
      return (
        <tr>
          <td>{country.Country}</td>
          <td>{country.NewConfirmed}</td>
          <td>{country.TotalConfirmed}</td>
        </tr>
      );
    });
const getInfo=()=>countries.map((country)=>{
返回(
{country.country}
{country.newconfirm}
{国家/地区}
);
});

const getInfo=()=>{
返回国家。地图((国家)=>{
返回(
{country.country}
{country.newconfirm}
{国家/地区}
);
});
};

您的
getInfo
不会返回任何内容

通过不在函数体周围使用
{}
来使用隐式返回,或者显式使用
return
语句

 const getInfo = () => countries.map((country) => {
      return (
        <tr>
          <td>{country.Country}</td>
          <td>{country.NewConfirmed}</td>
          <td>{country.TotalConfirmed}</td>
        </tr>
      );
    });
const getInfo=()=>countries.map((country)=>{
返回(
{country.country}
{country.newconfirm}
{国家/地区}
);
});

const getInfo=()=>{
返回国家。地图((国家)=>{
返回(
{country.country}
{country.newconfirm}
{国家/地区}
);
});
};