gpt4 book ai didi

javascript - React 空白文本节点不能作为 的子节点出现

转载 作者:行者123 更新时间:2023-11-29 23:00:57 25 4
gpt4 key购买 nike

我想用加密硬币符号创建表格,但我收到此错误 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

看起来我想要它,但它抛出了这个警告。最后我想要类似 https://www.coingecko.com/en 的东西但显然更简单:)

最佳答案

找到了。问题是符号状态是初始字符串我只是像这样将它转换为数组

this.state = {
symbol: []
}

关于javascript - React 空白文本节点不能作为 <tbody> 的子节点出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55670690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com