Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda