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

206
Visualizações
I keep getting Expected "`onClick` listener to be a function, instead got a value of `object` type." error and i dont know how to fix it
import React from 'react';
import useState from './App';
import username from './App';
import setUsername from './App';
import setAppState from './App';

function LoginPage(props) {

 const onClick = () => {
    props.onLogin(setUsername);

  }

  return (
    <div className="chat-login-page-container">
     <div className="chat-login-page-controls-container">
       <h4>Set your username</h4>
        <input type="text" 
               placeholder="Username"
               value={props.username} 
               username={username}
               setUsername={username}
           
               onChange={props.onChange} />
           
        <button type="button" disabled={username.length === 0} onClick='onClick'>Log 
 in</button>
      </div>
    </div>
  );
}

export default LoginPage;

I keep trying to fix the code with diffrent variables and trying to make it not a value and it just dosnt work. Im at a loss and dont know what to do.

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

0

  1. First, you should use object destructuring for props

    const {username, onChange, onLogin} = props;

  2. In component "button", the property "onClick" expects a function. With your code onClick='onClick', the property is getting a string and not a function. I'm not sure what the onClick function should do, but it should look somehow like this:

<button type="button" disabled={username.length === 0} onClick={()=>{onLogin(setUsername}}>Log in</button>
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