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

160
Views
How can i Show Back-End response in react?

How can I show the response of the following request?

function Submit(e) {
    e.preventDefault();
    axios
      .post(url, {
        email: data.email,
        password: data.password,
        confirmpassword: data.confirmpassword,
        first_name: data.first_name,
        last_name: data.last_name,
        mobile: data.mobile,
        birthday: data.birthday,
        gender: data.gender,
        profession: data.profession,
      })
      .then((res) => {
        console.log(res.data);
      });
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use the 'state' hook to hold your data. When it gets updated, it automatically updates the clients state (screen/gui).

If you want to run the code as soon as the page loads, use it in an effect hook.

import React, { useEffect, useState } from 'react';

export default function YourComponent() {

  const [yourObject, setYourObject] = useState({});

//optional
 useEffect({
    getData(null);
 },[]);
 
  function getData(e) {
    if(e)
      e.preventDefault();

    axios.post(url,
      {
        email: data.email,
        password: data.password,
        confirmpassword: data.confirmpassword,
        first_name: data.first_name,
        last_name: data.last_name,
        mobile: data.mobile,
        birthday: data.birthday,
        gender: data.gender,
        profession: data.profession,
      })
      .then((res) => {
        setYourObject(res.data)
      });
  }

  return (
   <div>
     <button onClick={e=>getData(e)}>
        Get Data
     </button>
    {if(Object.keys(yourObject).length > 0) &&
      <h1>First Name: </h1><p>{yourObject.first_name}</p>
      <h1>Last Name: </h1><p>{yourObject.last_name}</p>
      <h1>Birthday: </h1><p>{yourObject.birthday}</p>
      {/* ...etc. */}
    }
   </div>
  )
}
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!