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

127
Views
usestate not picking up updated value
function Profile() {


    const [userId, setUserId] = useState(localStorage.getItem("user_id"))
    const [fname, setFname] = useState()
    const instance = axios.create({baseURL: server});

    useEffect( ()=> {
      
      const getUserValues = async () => {

        const response = await instance.get(
          `Users?id=${userId}`

        )
          setFname(response.data[0].fname)
          console.log(response.data[0].lname)
      }
      getUserValues();
    },[])



    const editValues = {
      firstname: fname,
    };

    const [editUserValue, setEditValue] = useState(editValues);


    console.log(fname) return( <input className="form-control" type="text" name="firstname" value={editUserValue.firstname} )

I'm having issues on getting my editvalues to display in the input because of the rendering that react has on usestate. In the console.log(fname) i get first a undefined then another console log of the value that is needed. But i cant get that value to display on the input.

The updated value should be taken by editvalues, but editvalues only takes the non updated data.

Any suggestions?

about 4 years ago · Juan Pablo Isaza
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!