Reputation: 471
How to make VS Code autocomplete React component's prop types while using the component in JSX markup?
P.S.: I'm using JS, not TS.
Upvotes: 37
Views: 33654
Reputation: 273
for the class components you can use propTypes to do the job, you can follow this link for details -> Link
import PropTypes from 'prop-types';
class Greeting extends React.Component {
render() {
return (
<h1>Hello, {this.props.name}</h1>
);
}
}
Greeting.propTypes = {
name: PropTypes.string
};
Upvotes: 0
Reputation: 29829
You can also get intellisense support from PropTypes. You'll need to install prop-types
import React from "react"
import PropTypes from 'prop-types';
function Header(props) {
return <h1>{props.headerText}</h1>
}
Header.propTypes = {
headerText: PropTypes.string.isRequired
}
export default Header
Upvotes: 3
Reputation: 359
There is also option to use @params definition:
/**
*
* @param {{header: string, subheader: string, imageAlt: string, contentList: Array, orderLink: Object, contentLink: Object}} props
*/
export default function JumbotronMain(props) {...}
Upvotes: 12
Reputation: 2039
I noticed that if you have a stateless component and you get the props using ES6, when you use this component, you get the props with the autocomplete.
const Stateless = ({ prop1, prop2 }) => {
return (
<div></div>
)
}
Upvotes: 8