REACT create datepicker react - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution
join us

create datepicker using react


 1059

REACT


2

// you need to install:
npm install react-datepicker --save
npm install moment --save
npm install bootstrap --save

import React from "react";
import DatePicker from 'react-datepicker';
import moment from 'moment';

import 'react-datepicker/dist/react-datepicker.css';
import 'bootstrap/dist/css/bootstrap.min.css';

class App extends React.Component {

constructor (props) {
super(props)
this.state = {
startDate: moment()
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(date) {
this.setState({
startDate: date
})
}

handleSubmit(e) {
e.preventDefault();
let main = this.state.startDate
console.log(main.format('L'));
}

render() {
return (
<div className = "container">
<h3>React Datepicker Example</h3>
<form onSubmit={ this.handleSubmit }>
<div className="form-group">
<label>Select Date: </label>
<DatePicker
selected={ this.state.startDate }
onChange={ this.handleChange }
name="startDate"
dateFormat="MM/DD/YYYY"
/>
</div>
<div className="form-group">
<button className="btn btn-success">Add Date</button>
</div>
</form>
</div>
);
}
}

export default App;


By        
The power of the user (%)
13%



The most helpful REACT solutions

How to get client ip address using react ?How to get client ip address using react ?REACT

Click to see more ...

  19.2K     421

how to get the type of a device using react ?how to get the type of a device using react ?REACT

Click to see more ...

  2.1K     220

create digital clock reactcreate digital clock reactREACT

Click to see more ...

  1.6K     141

country dropdown using reactcountry dropdown using reactREACT

Click to see more ...

  1.1K     127

create alarm clock using reactcreate alarm clock using reactREACT

Click to see more ...

  5.1K     116

How to get latitude and longitude using react/javascript ?How to get latitude and longitude using react/javascript ?REACT

Click to see more ...

  951     108

get client country reactget client country reactREACT

Click to see more ...

  714     82

get ip address reactget ip address reactREACT

Click to see more ...

  939     81

time ago reacttime ago reactREACT

Click to see more ...

  534     74

detect mobile device reactdetect mobile device reactREACT

Click to see more ...

  526     58

Welcome aboard!
We are happy you are here and
wish you good net-raft!