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

171
Visualizações
React - onChange event & function not working on imported Input component

I have the following code/components. The onChange event on the imported Input component is not working, it doesn't get triggered. I have tried different solutions on the web but they don't work. However, If I try to render an element directly in the APP function rather than importing an external component, it works. What am I doing wrong? Thanks.

  • Input component

    import React from "react";
    
     export default function Input(event) {
        return <input />;
      }
    
  • Item component

    import React from 'react';
     export default function Item({text}) {
          console.log({text});
          return <li>{text}</li>
      }
    
  • App.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;

Folder structure:

Folder Structure

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

0

You passed that as a prop. Item component should be

 export default function Input(props) {
    return <input onChange={props.onChange}/>;
  }
about 4 years ago · Juan Pablo Isaza Relatório

0

From React Documentation

Remember to pass the prop into the <input /> element

function Welcome(props) {
    return <h1>Hello, {props.name}</h1>;
}

function App() {
    return (
        <div>
            <Welcome name="Sara" />
            <Welcome name="Cahal" />      
            <Welcome name="Edite" />    
        </div>
    );
}
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