My code right now picks a date, and this class is used in another file. Where it renders the date in a ddd D MMMM format. I want to change my code from a class to a react hook, and I'm not very sure how to do this. Here is the code:
import React, { Component } from "react";
import moment from "moment";
class DayPicker extends Component {
constructor(props) {
super(props);
this.state = { date: Date() };
}
componentDidMount() {
this.timerID = setInterval(() => this.tick(), 1000);
}
componentWillUnmount() {
clearInterval(this.timerID);
}
tick() {
this.setState({
date: Date(),
});
}
render() {
return (
<div className={style.dayPicker}>
{moment()
.add(daysToAdd ? daysToAdd : 0, "day")
.format("ddd D MMMM")}
</div>
);
}
}
export default DayPicker;
If someone manages to convert my code into react hooks, please explain the process to me as it would be a great change to learn more about react Hooks.