Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
React - what should be the propType of Material UI icon

I am going to pass MUI icon to component Test and I want to create Protype for the icon, but I am not sure what should be the correct proptype of the icon

App.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>
  );
}

Test.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

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It should be a PropTypes.element

Test.propTypes = {
  icon: PropTypes.element
};

Working Example:

Edit fervent-poitras-ubr96

about 4 years ago · Juan Pablo Isaza Denunciar

0

I'd go with PropTypes.element here if you want to be specific.

Typechecking with PropTypes

Test.propTypes = {
  icon: PropTypes.element,
};
// A React element.
optionalElement: PropTypes.element,

If you want to be a little more loose/general, then use PropTypes.node for anything that is renderable.

// Anything that can be rendered: numbers, strings, elements or an array
// (or fragment) containing these types.
optionalNode: PropTypes.node,

Edit react-what-should-be-the-proptype-of-material-ui-icon

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda