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

112
Views
react button click not firing

I'm trying to make a little login screen with functional React. I have an input button that I want to click and have the login post happen. For the life of me, I can't get the handler to fire. loginPressed just won't get called. I'm sure it's something easy that I'm overlooking.

import * as React from 'react';
import axios from 'axios'

export default function Login() {

  const [email, setEmail] = React.useState([]);
  const [password, setPassword] = React.useState([]);

  const loginPressed = () => {
    var body = {
      'email': email,
      'password': password
    }
    axios.post('login', body)
         .then(response => {

         })
  }

  return (
    <div>
      <p>Username:</p>
      <p><input type="text" name="email" onChange={(e) => {setEmail(e.target.value)}}/></p>
      <p>Password:</p>
      <p><input type="password" name="password" onChange={(e) => {setPassword(e.target.value)}}/></p>

      <p>
        <input type='button' value='Login' onClick={loginPressed}/>
      </p>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use form with onSubmit={loginPressed}. Instead of input use button html element with type of submit.

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!