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

109
Vistas
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
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