“proptypes” Código de respuesta

Proptypes matriz de objetos

MyComponent.propTypes = {
  items: PropTypes.arrayOf(
    PropTypes.shape({
      code: PropTypes.string,
      id: PropTypes.number,
    })
  ),
};
Outrageous Opossum

Proptypes

import PropTypes from "prop-types";

MyComponent.propTypes = {
  name: PropTypes.string,
  id: PropTypes.number.isRequired,
  img: PropTypes.string
  grades: PropTypes.arrayOf(PropTypes.number),
  friends: PropTypes.arrayOf(
    PropTypes.shape({
      id: PropTypes.number,
    })
  ),
  list: PropTypes.arrayOf(PropTypes.any),
};

MyComponent.defaultProps = {
  img: "https://picsum.phones/200/300",
}
Inexpensive Impala

proptypes

import PropTypes from 'prop-types';

class Greeting extends React.Component {
  render() {
    return (
      <h1>Hello, {this.props.name}</h1>
    );
  }
}

Greeting.propTypes = {
  name: PropTypes.string
};
Victorious

Reaccionar PesttHpes o

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

Respuestas similares a “proptypes”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código