React JS get current date

I want to display the current date in my component. My code works in the console, but the React console says:

"bundle.js: 14744 Uncaught RangeError: maximum call stack size exceeded

My component is as follows:

import React from 'react';
var FontAwesome = require('react-fontawesome');

export class Date extends React.Component {
    constructor() {
        super();

        var today = new Date(),
            date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();

        this.state = {
            date: date
        };
    }

    render() {
        return (
            <div className='date'>
                <FontAwesome name='calendar' />{this.state.date}
            </div>
        );
    }
}

Yes, I know that I'm pretty new, but maybe someone can help me. I google for hours --.-

thanks alot!

+6
source share
1 answer

, Date. new Date() , Date, ( this Date) - . , ... , .

Date , - , Calendar DateComponent.

, JavaScript : , , , . , Date Date, Date , Date, .

+11

Source: https://habr.com/ru/post/1016943/


All Articles