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

238
Visualizações
Why is my number coming up as an object when passed in the prop?

I have a component FooterScroll. And the main page is TvIndex.

This is the FooterScroll Component

const FooterScroll = (Id: number) => {
  const { event } = useEvent(Id);
  console.log('Id', Id);

  return (
    <Marquee speed={85}>
      <Grid container>
        {event?.notices.map((notice: EventNotice) => {
          if (notice.approved) {
            return (
              <>
                <Grid item px={4} key={notice.id}>
                  <CampaignIcon />
                </Grid>
                <Grid item alignItems="center">
                  {notice.body}
                </Grid>
              </>
            );
          }
        })}
      </Grid>
    </Marquee>
  );
};

export default FooterScroll;

This is the TvIndex Page

  import FooterScroll from 'components/pages/members/tv/scrolling-footer';

  const TvIndex: React.FC = () => {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <div className={classes.scrollFooter}>
        <FooterScroll Id={39324} />
      </div>
    </div>
  );
};

export default TvIndex;

For some reasons that I don't understand, when I pass in this any id number as a prop in my main component for FooterScroll, it gives me this error: Type '{Id: number;}' is not assignable to type 'number'. Then I decided to console log it inside FooterScroll, and it looks like after the id gets passed in TvIndex, it passes inside the FooterScroll component as an Object, like so: Id > Object { Id: 39324 }.

How can I solve this?

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

0

The argument passed to a React component is an object, whose properties are the props passed down by the caller. For example

<FooterScroll Id={39324} />

results in a prop object of:

{
  Id: 39324
}

React doing it this way allows for easily adding additional props, or properties to the props object, without changing the function signature much:

<FooterScroll Id={39324} someOtherProp="foo" />

results in a prop object of:

{
  Id: 39324,
  someOtherProp: 'foo'
}

So, you need to change the function definition to

const FooterScroll = ({ Id }: { Id: number }) => {

or do

const FooterScroll = (props: { Id: number }) => {
  const { Id } = props;
about 4 years ago · Juan Pablo Isaza Relatório

0

Your arguments to the FooterScroll are wrong. Try this:

  const FooterScroll = ({ Id }: { Id: number }) => {
  ...
  }

It should work.

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