Skip to content

Instantly share code, notes, and snippets.

@hchocobar
Last active January 30, 2023 14:55
Show Gist options
  • Save hchocobar/58a086f71774e91cd1174e2a38483a1b to your computer and use it in GitHub Desktop.
Save hchocobar/58a086f71774e91cd1174e2a38483a1b to your computer and use it in GitHub Desktop.
React - 02 - Proptypes & defaultProps

React - PropTypes $ defaultProps

Ejemplo

import React from "react";
import PropTypes from "prop-types";

const MyComponent = (props) => {
  return (
    <p>"Item: "{props.id}" - "{props.title}</p>
  );
};

MyComponent.propTypes = {
  id: PropTypes.number,
  title: PropTypes.string
};

MyComponent.defaultProps = {
  id: 1,
  title: "Título del ítem"
};

export default MyComponent;

Screenshot from 2022-11-29 13-19-59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment