In the project, I want to write down the current day and month like this:
Today is the 13th of September
When getting the current day, there is no error. But, when converting the current month number to the current month name, I get the error below:
Date.jsx:4 Uncaught RangeError: Maximum call stack size exceeded
My code in the Date component:
function Date() {
let date = new Date()
// console.log(dayDate.getDate())
const takeMonth = (month) => {
const monthName = date.setMonth(month - 1)
return monthName.toLocaleString("default", { month: "long" })
}
return <div> Date {takeMonth(3)}</div>
}
All answers are appreciated!
You are currently overriding the Date function by defining your own function called Date, so when you call new Date() inside your function, you are in fact calling your own override, which creates an infinite loop...
You should rename your own function like:
function getDate() {
let date = new Date()
/* rest of the code */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With