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

83
Visualizações
react parent components passing child a prop with different name

Sorry for the terrible question name, I'm wondering if there is a standard way of passing a different value for the same prop from different parents and if there's something wrong with the way I am spreading my props.

Parent 1:

<ChildComponent
prop1={prop1}
prop2={prop2}
paymentProcessingDate={Date.now()}
...passThroughProps
>

Parent 2 which has a prop carServiceDate

<ChildComponent
prop1={prop1}
prop2={prop2}
paymentProcessingDate={carServiceAppointment.date}
...passThroughProps
>

Both Parent1 and Parent2 make use of ChildComponent but need to pass in a different value for paymentProcessingDate. I'm receiving an error that the spread of passThroughProps will always overwrite paymentProcessingDate but the first time paymentProcessingDate is used or defined is in the call to ChildComponent. Any help or suggestions is really appreciated!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The ...passThroughProps must contain a value for paymentProcessingDate so TypeScript is complaining that your spread prop will overwrite whatever you explicitly set.

Try moving the spread to the top and see if that fixes it:

<ChildComponent
...passThroughProps
prop1={prop1}
prop2={prop2}
paymentProcessingDate={carServiceAppointment.date}
>

Or if possible, remove paymentProcessingDate from passThroughProps.

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