Hazem Alabiad
Hazem Alabiad

Reputation: 1052

How to annotate ReactJS State-full "class" Component props using JSDocs

How can I annotate the props in state-full "class" ReactJS components In order to get autocompletion inside render()? I tried the following however, it did not work:

  export default class MyComponent extends Component {

  /**
   * @param {object} props
   * @param {object} props.survey
   * @param {string} props.survey.name
   */
  constructor(props){
    super(props)
    // autocompletion works here
 }

  render() {
    // autocompletion does not work here

    return (
     console.log(this.props.survey.name)
    );
  }
}

Upvotes: 0

Views: 474

Answers (1)

Hazem Alabiad
Hazem Alabiad

Reputation: 1052

  /**
   * @typedef {object} props
   * @property {object} survey
   * @property {string} survey.name
   * @extends {Component<props>}
   */
  export default class MyComponent extends Component {

  constructor(props){
    super(props)
    // autocompletion works here
 }

  render() {
    // autocompletion should work here
    const {survey} = this.props;
    return (
     console.log(survey.name)
    );
  }
}

Upvotes: 1

Related Questions