gpt4 book ai didi

javascript - 错误: Type 'void' is not assignable to type 'ReactNode'

转载 作者:行者123 更新时间:2023-11-30 23:54:48 32 4
gpt4 key购买 nike

我在调用函数时遇到错误,这只是为了练习,所以我将所有内容都保存在 App.tsx 中。我的类(class)如下所示:

enum Actor {
None = '',
}

const initializeCard = () => {
//some logic here
return card;
}

export default class App extends Component<{}, State> {
state: State ={
card: initializeCard()
}

public renderRows = () => {
const { card } = this.state;
board.map((actor, index) => this.renderRow(actor, index));
}

public renderRow = (actor: Actor, index: number) => {
return(
<div className="cell">

</div>
)
}

public render() {
return (
<div className="App">
<div>
{ this.renderRows() } // Here I'm getting the error
</div>
</div>
)
}
}

我的Package.json看起来像:

"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"typescript": "~3.7.2"
}

完整错误如下:

Type 'void' is not assignable to type 'ReactNode'.ts(2322)index.d.ts(1348, 9): The expected type comes from property 'children'which is declared here on type'DetailedHTMLProps<HTMLAttributes, HTMLDivElement>'

我搜索了此错误的解决方案,发现 this但我无法用这个解决方案解决我的问题。请让我知道如何解决这个问题。谢谢。

最佳答案

您需要从函数中返回一些内容。

renderCell在哪里功能?也许你的意思是 renderRow

关于javascript - 错误: Type 'void' is not assignable to type 'ReactNode' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61131896/

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