Кнопка, которая меняет числа месяца
Не могу настроить кнопку right, чтобы менялись числа месяца в календаре, числа меняются после второго нажатия на кнопку/
Я ожидал что строка setMonth(prevMonth => prevMonth + 1), изменит переменную month сразу, а этого почему-то не происходит.
Приведен не весь код.
function App({
children
}) {
const [dateOne, setDateOne] = useState(new Date());
const [month, setMonth] = useState(dateOne.getMonth());
const [year, setYear] = useState(dateOne.getFullYear());
function right() {
console.log('ym', year, month);
setMonth(prevMonth => prevMonth + 1)
console.log('ym', year, month);
} //right
return ( <
div style = {
{
backgroundColor: "green",
margin: 3,
padding: 2,
height: 500
}
} >
<
ul >
<
/ul> {year}-{month + 1}
{ /* <button onClick = {()=>{left()}}>←</button><span>Месяц</span> */ } <
button onClick = {
() => {
right()
}
} > → < /button> <
TableOne arrCalendar = {
arrCalendar
}
/>
<
AreaOfText / >
{
children
}
<
/div>
);
} //App
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.2/umd/react-dom.production.min.js"></script>