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

107
Views
Checking propType against multiple custon propTypes

I'm having trouble determining what element is passed via the proptype

Here is my components (simplified):

const MyButton = (props) => {
  return ( <button id={props.title} onClick={props.cb}/> );
}

MyButton.propTypes = {
  title: PropTyps.string.isRequired,
  cb: PropTypes.func.isRequired
};

class MySelect extends React.Component {
    ...
    ...

    render() {
        return ( 
            <select value={props.value} >
                {this.props.options.map((option, index) => (
                    <option key={index} value={option.text}>{options.text}</option>
                ))}
            </select>
       );
    }
}

MySelect.propTypes = {
    value: PropTypes.string.isRequired,
    options: PropTypes.arrayOf(PropTypes.shape({
        text: PropTypes.string.isRequired
    })).isRequired
};

My issue is in the render function of my main class, I need to determine what typeof props I have in order to know what to render.

export default class MyApp extends React.Component {
    ...
    ...
    
    render() {
        return (
            <div>
--> Wrong               {component instanceof MyButton && component}
--> Wrong               {component instanceOf MyButton && <MySelect value={component.props.value} options={component.props.options />
            </div>

    }
}

MyApp.propTypes = {
    component: PropTypes.oneOfType([
        PropTypes.instanceOf(MyButton),
        PropTypes.instanceOf(MySelect)
    ]).isRequired
};

I'm getting Failed prop type

about 4 years ago · Juan Pablo Isaza
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!