Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda