JSDoc 来描述 React useState?

问题描述 投票:0回答:1

如何使用 JSDoc 描述 React 状态?

换句话说,如何将其简化为一句台词?

/** The animal you're with */
let animal;
let setAnimal;
[animal, setAnimal] = useState()

换句话说...

/** what do you put here to describe `animal`? */
const [animal, setAnimal] = useState()
javascript reactjs jsdoc
1个回答
0
投票

试试这个

  /**
   * @typedef Man
   * @property {string} name
   * @property {number} age
   */

  /**
   * @type {[Man, React.Dispatch<Man>]}
   */
  const [data, setData] = useState({ name: "ben", age: 20 });
© www.soinside.com 2019 - 2024. All rights reserved.