[英]validateDOMNesting(…): Text nodes cannot appear as a child of <tbody>
i don't know why i'm receiving this warning?我不知道为什么我会收到这个警告? and because of this i can't see updated table..因此我看不到更新的表格..
Warning: validateDOMNesting(...): Text nodes cannot appear as a child of <tbody>.
In some cases I saw that it is about some white spaces and different table tags, but I don't see how this applies in here.在某些情况下,我看到它是关于一些空格和不同的表格标签,但我不明白这在这里如何应用。
TableCom桌康
import { Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@material-ui/core'
import React from 'react'
export const Countries = ({details}) => {
return (
<TableContainer component={Paper}>
<Table aria-label="simple table">
<TableHead>
<TableRow>
<TableCell align='right'>Country</TableCell>
<TableCell align='right'>Total Infected</TableCell>
<TableCell align='right'>Total Recoverd</TableCell>
<TableCell align='right'>Total Deaths</TableCell>
</TableRow>
</TableHead>
<TableBody>
{details.length && details.map((detail) => {
return (
<TableRow>
<td key={detail.id}>{detail.cases}</td> : null
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
)
}
App.js for state and passing props state和传递道具的 App.js
import React, { useEffect, useState } from 'react'
import { Appbar } from './components/pageOne/Appbar'
import { Cards } from './components/pageOne/Cards'
import { fetchData, fetchCountries } from './components/FetchDataFromApi'
import { Countries } from './components/pageOne/TableCom'
function App() {
const [data, setData] = useState({})
const [details, setDetails] = useState([])
useEffect(() => {
(async () => {
const fetchAPI = await fetchCountries();
setDetails(fetchAPI)
})()
}, []);
useEffect(() => {
(async () => {
const fetchedData = await fetchData();
setData(fetchedData)
})()
}, [])
return (
<>
<Appbar />
<Cards data = {data} />
<Countries details = {details} />
</>
)
}
export default App;
any solution to solve this... codeSandBox解决这个问题的任何解决方案... codeSandBox
The problem is in the way you handle the response which you're getting from the api.问题在于您处理从 api 获得的响应的方式。 You're returning an object instead of an array.您返回的是 object 而不是数组。
https://codesandbox.io/s/silly-dan-7iusu https://codesandbox.io/s/silly-dan-7iusu
Here is a working sandbox, I just get all the data from the response and pass it down.这是一个工作沙箱,我只是从响应中获取所有数据并将其传递下来。 You can also create an array yourself, only with the data you need.您也可以自己创建一个数组,只使用您需要的数据。 But currently you're passing an object.但目前您正在传递 object。
Look at index.js
in fetchApi
.查看fetchApi
中的index.js
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.