ES6 反应组件的 JSDoc
JSDoc for a ES6 react component
我认为 React 组件的 JSDoc 注释可能如下所示:
/**
* My component...
*
* @namespace MyComponent
* @memberof app.components
*/
app.components.MyComponent = React.createClass({
})
但是如果我使用的是 ES6,它会是什么样子呢?
/**
* My component...
*
* @namespace MyComponent
* @memberof ??
*/
class MyComponent extends Component {
/**
* PropTypes
* @param {string} element
*/
static propTypes = {
element: PropTypes.object
}
/**
* Constructor
* How to take care about onChange and states?
*/
constructor () {
super()
this.onChange = this.onChange.bind(this)
this.state = {
anything: true
}
}
}
我也不明白如何记录静态 propTypes 和构造函数...
'best' 文档可能缺少更多标签吗?
由于您使用的是 ES6 模块,因此无需指定命名空间或“@memberof”。
有一个jsdoc-react but i would recommend to use an interactive component style guide like styleguidist which handle both jsdoc and proptypes. According to their documentation,他们不评论构造函数。
您可以将 JSDoc 与更好的文档一起使用 theme/plugin
- 它自动生成文档(自述文件和 HTML 页)
- 高度可定制
- 组件的实时预览
在这里查看:https://www.inkoop.io/blog/a-guide-to-js-docs-for-react-js/
我认为 React 组件的 JSDoc 注释可能如下所示:
/**
* My component...
*
* @namespace MyComponent
* @memberof app.components
*/
app.components.MyComponent = React.createClass({
})
但是如果我使用的是 ES6,它会是什么样子呢?
/**
* My component...
*
* @namespace MyComponent
* @memberof ??
*/
class MyComponent extends Component {
/**
* PropTypes
* @param {string} element
*/
static propTypes = {
element: PropTypes.object
}
/**
* Constructor
* How to take care about onChange and states?
*/
constructor () {
super()
this.onChange = this.onChange.bind(this)
this.state = {
anything: true
}
}
}
我也不明白如何记录静态 propTypes 和构造函数...
'best' 文档可能缺少更多标签吗?
由于您使用的是 ES6 模块,因此无需指定命名空间或“@memberof”。
有一个jsdoc-react but i would recommend to use an interactive component style guide like styleguidist which handle both jsdoc and proptypes. According to their documentation,他们不评论构造函数。
您可以将 JSDoc 与更好的文档一起使用 theme/plugin
- 它自动生成文档(自述文件和 HTML 页)
- 高度可定制
- 组件的实时预览
在这里查看:https://www.inkoop.io/blog/a-guide-to-js-docs-for-react-js/