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

82
Visualizações
How to define custom props in a react functional component with typescript?

I just started a new react project with typescript and I'm having difficulty defining a custom prop in a functional component.

I looked up how to define custom props and I found a way of defining an interface detailing the type of prop I'm passing in to the function, but when I try to run it on my main App, I get an error saying

Type '{ digit: number; }' is not assignable to type 'IntrinsicAttributes'. Property 'digit' does not exist on type 'IntrinsicAttributes'. TS2322

My code :

import React from 'react';
import Button from '@mui/material/Button';
export {}


interface NumberButton {
  digit:number,
}

function NumberButton(props:NumberButton){
  return (
    <Button variant="contained" color="primary">{props.digit}</Button>
  )
}
import React from 'react';
import ReactDOM from 'react-dom';
import ClearButton from './Components';
import NumberButton from './Components';
export default function App(){

  return (
    <div>
      <ClearButton/>
      <NumberButton digit={1}/>
    </div>
  )
}

I'm trying to get more familiar with functional components after using hooks and I'm hooked on using them.

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

0

export {}

Currently you're not exporting the NumberButton component, so that's the main thing that needs fixing. Additionally, you're using the same variable name for both the component and the props. Try this:

import React from 'react';
import Button from '@mui/material/Button';

interface NumberButtonProps {
  digit: number,
}

function NumberButton(props: NumberButtonProps){
  return (
    <Button variant="contained" color="primary">{props.digit}</Button>
  )
}

export default NumberButton;
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