• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

156
Views
Reaccionar: el evento y la función onChange no funcionan en el componente de entrada importado

Tengo el siguiente código/componentes. El evento onChange en el componente Input importado no funciona, no se activa. He probado diferentes soluciones en la web pero no funcionan. Sin embargo, si trato de representar un elemento directamente en la función de la aplicación en lugar de importar un componente externo, funciona. ¿Qué estoy haciendo mal? Gracias.

  • Componente de entrada

     import React from "react"; export default function Input(event) { return <input />; }
  • componente del artículo

     import React from 'react'; export default function Item({text}) { console.log({text}); return <li>{text}</li> }
  • Aplicación.JS

 import React, { useState } from "react"; import "./App.css"; import Input from "./input"; import Item from "./item"; function App() { const [text, setText] = useState(); function handleChange(event){ console.log(event.target.value); setText(event.target.value); } return ( <div className="App"> <h1>JSX will go here!</h1> <Input onChange={ event => handleChange(event)} /> <Item text={text} /> </div> ); } export default App;

Estructura de carpetas:

Estructura de carpetas

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Pasaste eso como apoyo. El componente del artículo debe ser

 export default function Input(props) { return <input onChange={props.onChange}/>; }
almost 3 years ago · Juan Pablo Isaza Report

0

De la documentación de React

Recuerda pasar el accesorio al elemento <input />

 function Welcome(props) { return <h1>Hello, {props.name}</h1>; } function App() { return ( <div> <Welcome name="Sara" /> <Welcome name="Cahal" /> <Welcome name="Edite" /> </div> ); }
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error