如果我有箭头函数,包裹在 React
useCallback
中,我该如何用 JSDoc 来记录它?
const floopPig = useCallback((pigKey, floopCost) => {
const pigAbility = pigs[pigKey];
if (pigAbility.floopCost < magicPoints) {
return pigAbility.activate()
} else {
throw new Error('Not enough magic points');
}
}, [pigs, magicPoints])
我一直在 VSCode 中尝试此操作,但将鼠标悬停在上面时没有显示任何内容:
/**
* Floops a pig
* @callback
* @param {number} pigKey unique key for each pig
* @param {number} floopCost how much the ability costs to activate
*/
我认为我已正确遵循 @callback
@callback
的目的是错误的?
我该如何记录这个?
我已经成功记录了回调函数本身。
const getNewToken = useCallback(
/**
* Requests a token, either by the normal flow or with a refresh token
* @param {URLSearchParams} axiosBody The body of the axios request
*/
async (axiosBody) => {
//Function
}, [myVar]);
在代码的下方,当我调用我的函数时,我可以看到智能感知发挥了它的魔力。我不是 100% 确定这是最好的答案,但这是我找到的最好的答案