[英]React whitespace text nodes cannot appear as a child of <tbody>
I want to create table with crypto coins symbols but I get this error Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <tbody>. Make sure you don't have any extra whitespace between tags on each line of your source code.
我想用加密硬币符号创建表,但出现此错误Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <tbody>. Make sure you don't have any extra whitespace between tags on each line of your source code.
Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <tbody>. Make sure you don't have any extra whitespace between tags on each line of your source code.
import React, { Component } from 'react'
class Main extends Component {
constructor(props) {
super(props)
this.state = {
symbol: ''
}
}
createTable(coins) {
}
getDataFromApi() {
const url = 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=USD&order=market_cap_desc&per_page=50&page=1&sparkline=false'
fetch(url)
.then(response => response.json())
.then(data => {
this.setState({
symbol: data.map(coin => {
return <tr key={coin.symbol}><td>{coin.symbol}</td></tr>;
})
}, () => console.log(this.state.symbol))
})
}
componentDidMount() {
this.getDataFromApi()
}
render() {
return (
<div><table><tbody>{this.state.symbol}</tbody></table></div>
)
}
}
export default Main
It looks like I want it to but it throws this warning. 看起来像我想要的那样,但是会引发此警告。 In the end I want something like https://www.coingecko.com/en but obviously simpler :) 最后,我想要类似https://www.coingecko.com/en的东西,但显然更简单:)
Found it. 找到了。 Problem was symbol state was initialy string I just converted it to array like so 问题是符号状态是初始字符串,我只是将其转换为数组,如下所示
this.state = {
symbol: []
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.