proptypes array of objects
MyComponent.propTypes = {
items: PropTypes.arrayOf(
PropTypes.shape({
code: PropTypes.string,
id: PropTypes.number,
})
),
};
proptypes array of objects
MyComponent.propTypes = {
items: PropTypes.arrayOf(
PropTypes.shape({
code: PropTypes.string,
id: PropTypes.number,
})
),
};
use propTypes in react function
import React from 'react';
import { PropTypes } from 'prop-types';
const student = (props) => {
return (
<div>
<p>Student Name: {props.name}</p>
<p>Age: {props.age}</p>
</div>
);
};
student.propTypes = {
name: PropTypes.string,
age: PropTypes.number
};
export default student;
react proptypes
import PropTypes from 'prop-types';
class Greeting extends React.Component {
render() {
return (
<h1>Hello, {this.props.name}</h1>
);
}
}
Greeting.propTypes = {
name: PropTypes.string
};
proptypes.objectof
Pokemon.propTypes = {
pokemon: PropTypes.shape({
name: PropTypes.string,
id: PropTypes.number,
base_stamina: PropTypes.number,
base_defense: PropTypes.number
})
}
proptypes for a react component
//You can now use `PropTypes.elementType`
// to validate for Component type props
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us