Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  7] [ 1]  / answers: 1 / hits: 17930  / 7 Years ago, thu, july 13, 2017, 12:00:00

I think the JSDoc comment for a react component could look like this:



/**
* My component...
*
* @namespace MyComponent
* @memberof app.components
*/
app.components.MyComponent = React.createClass({
})


But how should it look like if I'm using 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
}
}
}


Also I do not understand how to document the static propTypes and the constructor...



Are there more tags missing for the 'best' documentation possible?


More From » reactjs

 Answers
11

Since you are using ES6 modules, you don't need to specify the namespace nor the '@memberof'.



There is a 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, they don't comment constructor.



Here is a list of multiples react living style guide


[#57097] Tuesday, July 11, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
benitoh

Total Points: 150
Total Questions: 113
Total Answers: 104

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
benitoh questions
Sun, Mar 21, 21, 00:00, 3 Years ago
Mon, May 13, 19, 00:00, 5 Years ago
;