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.
Using PropTypes in React PropTypes is React's internal mechanism for adding type checking to components. React components use a special property named propTypes to set up type checking. When props are passed to a React component, they are checked against the type definitions configured in the propTypes property.
You can pass a component as props in React by using the built-in children prop. All elements you pass between the opening and closing tags of a component get assigned to the children prop. Copied!
A component cannot update its own props unless they are arrays or objects (having a component update its own props even if possible is an anti-pattern), but can update its state and the props of its children.
Not only can JSX elements be passed as props to components, but we can also pass other components as props.
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) {...}
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> ) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With