1MyComponent.propTypes = {
2 items: PropTypes.arrayOf(
3 PropTypes.shape({
4 code: PropTypes.string,
5 id: PropTypes.number,
6 })
7 ),
8};
1import React from 'react';
2import { PropTypes } from 'prop-types';
3
4const student = (props) => {
5 return (
6 <div>
7 <p>Student Name: {props.name}</p>
8 <p>Age: {props.age}</p>
9 </div>
10 );
11};
12
13student.propTypes = {
14 name: PropTypes.string,
15 age: PropTypes.number
16};
17
18export default student;
1// proptypes using class component
2Detaljer.PropTypes = {
3 detaljer: PropTypes.string.isRequired,
4 feilkode: PropTypes.string,
5 removeEvent: PropTypes.string.isRequired
6};
7
8// proptypes using function component
9Detaljer.propTypes = {
10 detaljer: PropTypes.string.isRequired,
11 feilkode: PropTypes.string,
12 removeEvent: PropTypes.string.isRequired
13};
1Pokemon.propTypes = {
2 pokemon: PropTypes.shape({
3 name: PropTypes.string,
4 id: PropTypes.number,
5 base_stamina: PropTypes.number,
6 base_defense: PropTypes.number
7 })
8}
1const Camper = (props) => {
2 return (
3 <p>{props.name}</p>
4 )
5};
6
7Camper.defaultProps = {name: 'CamperBot'}
8Camper.propTypes = { name: PropTypes.string.isRequired}
9