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

168
Views
Why the function is invoked for every input in React component?

I try to learn react component rendering but the problem is that I have a login page with 2 input field and 1 button as:

function LoginPage() {

    const [username, changeUsername] = useState('');
    const [password, changePassword] = useState('');

    const loginRequest = async (username, password) => {
        let response = await service.loginRequest(username, password);
        console.log(response);
    }

    return (
        <Card hoverable className='transaction-button-card'>
            <h1>Enter username and password</h1>
            <input type="text"
                   placeholder="Username"
                   onChange={e => changeUsername(e.target.value)}
                   value={username}></input>
            <input type="text"
                   placeholder="Password"
                   onChange={e => changePassword(e.target.value)}
                   value={password}></input>
            <Button onClick={loginRequest(username, password)}
                    className='withdraw-deposit-button'>Login/Deposit</Button>
        </Card>
    );
}

export default LoginPage;

When the page is rendered the function loginRequest(username, password) automatically triggered once and for every input characters to input fields are also triggering the same function and sending request for each input char. How can I solve this problem? (I don't want to send request automatically when the page is opened and send request with only with button). I would appreciate if you define the problem.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

` function LoginPage() {

const [username, changeUsername] = useState('');
const [password, changePassword] = useState('');

const loginRequest = async (username, password) => {
    let response = await service.loginRequest(username, password);
    console.log(response);
}

return (
    <Card hoverable className='transaction-button-card'>
        <h1>Enter username and password</h1>
        <input type="text"
               placeholder="Username"
               onChange={e => changeUsername(e.target.value)}
               value={username}></input>
        <input type="text"
               placeholder="Password"
               onChange={e => changePassword(e.target.value)}
               value={password}></input>
        <Button onClick={() => loginRequest(username, password)}
                className='withdraw-deposit-button'>Login/Deposit</Button>
    </Card>
);

}

export default LoginPage; `

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!