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}
{国家/地区}
);
});
};