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

268
Views
Uncaught Error: Objects are not valid as a React child (found: [object Promise])

Uncaught Error: Objects are not valid as a React child (found: [object Promise]).

import React, { useState,useEffect } from 'react';
import './App.css';

async function Login() {
const [username,setUsername] = useState("")
const [password,setPassword] = useState("")


async function handleSubmit({event) {
event.preventDefault
 fetch("http://localhost:3001/api/login",{
  method:"post",
  headers:{
    "Content-Type" : "application/json"
  },
  body:JSON.stringify({username:username,password:password})
})
const data = await response.json()
console.log(data.username)

} 



  return (
    <div className="App">
      <form onSubmit={handleSubmit}>

        <input placeholder="username" value={username} onChange={ e => setUsername(e.target.value)} />
        <input placeholder="password " value={password} onChange={ e => setPassword(e.target.value)}/>
        <button  type='submit' >Submit</button>
      </form>
    </div>
  );
}

export default Login;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you forgot put await before calling method

async function handleSubmit(event) {
event.preventDefault()
 let response = await fetch("http://localhost:3001/api/login",{
  method:"post",
  headers:{
    "Content-Type" : "application/json"
  },
  body:JSON.stringify({username:username,password:password})
})
const data = await response.data
console.log(data.username)

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