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

207
Views
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 answers
Answer question

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 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!