I am documenting my React Native components, but I don't know how to do it properly.
For the documentation generation, I am using jsdoc/better-docs, which is supposedly able to collect the comments you leave on your PropTypes and include them in the documentation. But... due to incompatibility issues, it is not possible to carry out this strategy in React Native, and, therefore, the PropTypes are not included in the documentation.
How do you document this React component using JSDOC?
/**
* ??
*/
function Cat({ name, color = "#000" }) {
return <View />;
}
Cat.propTypes = {
name: PropTypes.string.isRequired,
color: PropTypes.string,
};
I was doing the following:
/**
* The cat properties.
*
* @typedef {object} Props
* @property {string} name - The cat name.
* @property {string} [color="#000"] - The cat color.
*/
/**
* Cat component.
*
* @type {React.FC<Props>}
* @returns {React.ReactElement} The cat.
*/
function Cat({ name, color = "#000" }) {
return <View />;
}
Cat.propTypes = {
/** The cat name. */
name: PropTypes.string.isRequired,
/** The cat color. */
color: PropTypes.string,
};
But I am feeling that prop-types is useless after adding the type definitions (?).
How do you document your react components?
PropTypes.objectin thecomponent.propTypes, I get multiple annoying linter warnings, something that makes me doubt about the parallel use of jsdoc and proptypes.