简体   繁体   English

在 TSDoc 中键入 React 道具的正确格式是什么?

[英]What is the proper format for typing React props in TSDoc?

I'm trying to apply the TSDoc standard for comments to a React project written in Typescript (with an eye towards generating documentation with Typedoc), but can't find any definitive answers for the preferred way to annotate a React props object.我正在尝试将 TSDoc 标准用于评论用 Typescript 编写的 React 项目(着眼于使用 Typedoc 生成文档),但找不到任何明确的答案来注释 React props object 的首选方法。 I've got this so far, where MyProps is an interface:到目前为止,我已经有了这个,其中MyProps是一个接口:

/**
 * Description of my function component
 * @param props - React props
 */
export default function MyComponent(props: MyProps) { ...

Is there a preferred method?有首选方法吗?

You want to document the props interface, and not the component itself.您想要记录道具接口,而不是组件本身。 Which means this is the same as documenting fields of an interface.这意味着这与记录接口的字段相同。

import React from 'react'

interface FooProps {
  /** Testing 123 */
  foo: string
}

function Foo({foo}: FooProps) {
  return <>{foo}</>
}

<Foo foo="bar" />

When you hover over foo= on the last line, you should see the documentation.当您在最后一行的foo=上使用 hover 时,您应该看到文档。

在此处输入图像描述

Playground example. 游乐场示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM