Answers for "react props types"

3

proptypes array of objects

MyComponent.propTypes = {
  items: PropTypes.arrayOf(
    PropTypes.shape({
      code: PropTypes.string,
      id: PropTypes.number,
    })
  ),
};
Posted by: Guest on September-03-2020
6

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;
Posted by: Guest on March-17-2020
-1

prop-types

npm install --save prop-types
Posted by: Guest on December-23-2020
1

import prop-types

import PropTypes from 'prop-types'; // ES6var PropTypes = require('prop-types'); // ES5 with npm
Posted by: Guest on June-27-2021
1

ts react props type

type Props = {
  size: string;
}

const Component = ({ size = 'medium' }: Props) => (
  <div className={cn('spinner', size)} />
);
Posted by: Guest on March-02-2021
4

react propthpes or

size: PropTypes.oneOfType([
  PropTypes.string,
  PropTypes.number
]),
Posted by: Guest on April-03-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language