Voy a pasar el icono de MUI al componente Test y quiero crear un Protipo para el icono, pero no estoy seguro de cuál debería ser el tipo de propiedad correcto del icono.
Aplicación.js
import "./styles.css"; import VisibilityIcon from "@material-ui/icons/Visibility"; import Test from "./Test"; export default function App() { return ( <div className="App"> <Test icon={<VisibilityIcon />} /> </div> ); }Prueba.jsx
import PropTypes from "prop-types"; function Test(props) { const { icon } = props; return ( <div> Icon: {icon} </div> ); } Test.propTypes = { // icon: ?????? }; export default Test;https://codesandbox.io/s/intelligent-curie-8mtbw?file=/src/Test.jsx:0-213
Iría con PropTypes.element aquí si quieres ser específico.
Comprobación de tipos con PropTypes
Test.propTypes = { icon: PropTypes.element, };// A React element. optionalElement: PropTypes.element,
Si desea ser un poco más flexible/general, use PropTypes.node para cualquier cosa que se pueda renderizar.
// Anything that can be rendered: numbers, strings, elements or an array // (or fragment) containing these types. optionalNode: PropTypes.node,