How to Show the Current Year With React

PHOTO EMBED

Thu Oct 27 2022 02:33:01 GMT+0000 (Coordinated Universal Time)

Saved by @jayakrishna #howtoshowthe current year with react #react.js #currentyear

=> Simply add the following code inside your render function, like this::

class ShowCurrentYear extends React.Component {
  render() {
    return <div>{new Date().getFullYear()}</div>;
  }
}
...................
=> You could also create the get current year function outside of your render function, like this:
showCurrentYear() {
    return new Date().getFullYear();
}
...................
=> And then insert the output inside your render function wherever you want to show the current year in your app, like this:
<div>{this.showCurrentYear()}</div>
content_copyCOPY