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

126
Views
setState(Date) isnt working, cant figure out why?

check out the following block of code:

const [doj, setDoj] = useState(Date);
const handleEmployeeNumberChange = async (e, value, name) => {
        if (name === 'Employee Number') {
            const employee = await employeeServices.getByNumber(value);
            formik.setFieldValue('Employee Name', employee['Personal Information']['Employee Name']);
            formik.setFieldValue('Date of Joining', employee.Company['Date of Joining']);
            setDoj(new Date(employee.Company['Date of Joining']));
            console.log(new Date(employee.Company['Date of Joining']));
            console.log(doj);
            const element = { target: { name, value } };
            formik.handleChange(element);
        }
    };

So what im trying to do is, when the employee number changes, i want to update the state of a variable by the name of 'doj'. but That line isnt working for some reason. The output is shown below:

enter image description here

As you can see the second console log is the value of doj, which is its default value, which is why setDoj didnt work for some reason. Please Help!

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!