Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda