Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!