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

184
Vistas
React text state doesnt update immediately

i am trying to update the text and show the month, the calander updates but the month doesnt update untill i click the next month button twice, but if i click the next month button twice the month is also changed twice in the calander and it shows the previous month on the header.

This is The March month

enter image description here

This is April Month but the month shown is March.

enter image description here

this is my Code

const [showmonth, setShowMonth] = useState(moment().format("MMMM-YYYY"));
const [dateValue, setDateValue] = useState(moment());

const increaseMonth = () => {
    setDateValue(moment(dateValue).add(1, "M"));
    onDateChange(dateValue);
  };
   function onDateChange(value) {
    setShowMonth(value.format("MMMM-YYYY"));
  }
<RightOutlined
                  style={{
                    fontSize: "23px",
                    fontWeight: "700",
                    cursor: "pointer",
                  }}
                  onClick={increaseMonth}
                />

Please Help i am a beginner

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of making separate states for your date object and the current month, why not just keep the dateValue as the only state and get the month from that.

const [dateValue, setDateValue] = useState(moment());

const increaseMonth = () => {
    setDateValue(moment(dateValue).add(1, "M"));
};

Then, you can have the value of your month be

dateValue.format("MMMM-YYYY")

This has less code and you only have to update the date object and then your month will update when the days update.

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