In my react component I have an input field of type date. When a date is chosen it will be saved in state. In another place I want to add a certain number of days to this date and display it. I found Javascript solutions like this one (Add days to JavaScript Date) but unfortunately was not able to put it to use in my react/state environment. Any help on how to achieve this would be appreciated. Thanks!
Sidenote: I am using a local http server to load form.js
index.html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
</head>
<body>
<div class="form-container container col-8 my-4"></div>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<!-- Load our React component. -->
<script type="text/babel" src="form.js" crossorigin></script>
</body>
form.js
'use strict';
const e = React.createElement;
class testForm extends React.Component {
constructor(props) {
super(props);
this.state = {
birthday: ''
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({
birthday: event.target.value
});
}
render() {
return (
<form>
<div className="row">
<div className="form-group">
<label htmlFor="birthday">Birthday</label>
<input type="date" className="form-control" id="birthday" value={this.state.birthday} onChange={this.handleChange} placeholder="TT.MM.JJJJ" />
</div>
</div>
<div>Show date +7 days</div>
<div>{this.state.birthday}</div>
</form>
);
}
}
const domContainer = document.querySelector('.form-container');
ReactDOM.render(e(testForm), domContainer);