我记录了我对React的tic-tac-toe教程的复制,我不明白为什么我的函数的参数显示为布尔值(使用JSDocs),而事实并非如此。
这是我的函数的代码:
/**Return the game board.
*
* @param {boolean} xIsNext Allows to show a text that tell which player is the next.
* @param {string[]} squares The current board which will be update at the next action.
* @param {*} onPlay A function that allows to re-render the board.
* @returns the JSX structure of the board.
*/
function Board({xIsNext, squares, onPlay}) {
// ...
}
事实上它是在花括号中吗?或者是React的存在?还是其他原因?
因为
Board
组件采用单 props 参数。不是多参数
最好为
BoardProps
定义一个类型,如下所示
/**
* The board properties.
*
* @typedef {object} BoardProps
* @property {boolean} xIsNext Allows to show a text that tell which player is the next.
* @property {string[]} squares The current board which will be update at the next action.
* @property {*} onPlay A function that allows to re-render the board.
* /
/**
* Board component
*
* @param {BoardProps} props The board props
* @returns {React.ReactElement}
*/
function Board({ xIsNext, squares, onPlay }) {
// ...
}