准备实现一下 井字旗 https://react.docschina.org/learn/tutorial-tic-tac-toe 遇到这个问题
import "./App.less"
import {useState} from "react";
function Square(onclickCallBack: ????) { // <<------------- 这里怎么写类型
const [content, contentSetter] = useState("")
return (
<button className="square" onClick={() => {
onclickCallBack(contentSetter)
}}>{content}</button>
)
}
function App() {
const [square, squareSetter] = useState("X")
function change(f: (c: string) => void): void {
f(square)
square === "X" ? squareSetter("O") : squareSetter("X")
}
return (
<div id="main">
<div className="board-row">
<Square onclickCallBack={change}/>
<Square onclickCallBack={change}/>
<Square onclickCallBack={change}/>
</div>
<div className="board-row">
<Square onclickCallBack={change}/>
<Square onclickCallBack={change}/>
<Square onclickCallBack={change}/>
</div>
<div className="board-row">
<Square onclickCallBack={change}/>
<Square onclickCallBack={change}/>
<Square onclickCallBack={change}/>
</div>
</div>
)
}
export default App;