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

143
Vistas
type for useState with callback - Type has no call signatures

I am using useState with a callback:

interface Props {
  label: string;
  key: string;
}

const [state, setState] = useState<Props[]>([]);


setState((prev : Props[]) => [...prev, newThing])

I get the error:

2349: This expression is not callable. Type 'Props' has no call signatures.

I'm not sure how to define a call signature inside the Props interface/type, what is the best approach to resolve this?

Edit:

This is how I am using it inside my code:

Interface:

interface TagProps {
  left: string;
  top: string;
  backgroundColor: string;
  rotation: number;
  label: string;
  key: string;
}

Home.tsx

const Home: FC<TagProps> = (setState, state: TagProps[]) => {
  const createTag = (e: any) => {
    const tagSpec = {
      left: e.clientX + "px",
      top: e.clientY + "px",
      backgroundColor: randomColour(colors),
      rotation: randomNumber(-20, 20),
      label: tech[randomNumber(0, tech.length - 1)],
      key() {
        return this.label + this.backgroundColor;
      },
      position: "absolute",
    };
    setState((prev: TagProps[]) => [...prev, tagSpec]);
  };

...

}

App.tsx

function App() {
  const [tag, setTag] = useState<TagProps[]>([]);

  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Layout />}>
          <Route index element={<Home setState={setTag} state={tag} />} />
          <Route path="/blog" element={<Blog />} />
        </Route>
      </Routes>
    </BrowserRouter>
  );
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You have to desctucture your props

// from
const Home: FC<TagProps> = (setState, state: TagProps[]) => {

// to
const Home: FC<TagProps> = ({ setState, state }) => {

Also I wouldn't pass setState down to the component

about 4 years ago · Juan Pablo Isaza Denunciar

0

React Functional Component's property are under the first param, you can do this to get them

const Home = (props) => {
  const { state, setState } = props;

  // setState(...)
}
about 4 years ago · Juan Pablo Isaza Denunciar
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