Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
escriba para useState con devolución de llamada: el tipo no tiene firmas de llamada

Estoy usando useState con una devolución de llamada:

 interface Props { label: string; key: string; } const [state, setState] = useState<Props[]>([]); setState((prev : Props[]) => [...prev, newThing])

me sale el error:

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

No estoy seguro de cómo definir una firma de llamada dentro de la interfaz/tipo de Props, ¿cuál es el mejor enfoque para resolver esto?

Editar:

Así es como lo estoy usando dentro de mi código:

Interfaz:

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

Inicio.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]); }; ... }

Aplicación.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 answers
Answer question

0

Tienes que desestructurar tus accesorios.

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

Además, no pasaría setState al componente

about 4 years ago · Juan Pablo Isaza Report

0

Las propiedades de React Functional Component están bajo el primer parámetro, puede hacer esto para obtenerlas

 const Home = (props) => { const { state, setState } = props; // setState(...) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!