using prop types in functional components code example

Example 1: how to make proptypes either or

size: PropTypes.oneOfType([
  PropTypes.string,
  PropTypes.number
]),

Example 2: use propTypes in react function

import React from 'react';
import { PropTypes } from 'prop-types';

const student = (props) => {
  return (
    

Student Name: {props.name}

Age: {props.age}

); }; student.propTypes = { name: PropTypes.string, age: PropTypes.number }; export default student;

Example 3: how to make proptypes either or

size: PropTypes.oneOfType([
    PropTypes.number,
    PropTypes.oneOf([ 'SMALL', 'LARGE' ]),
]),

Tags:

Misc Example