BootStrap DatePicker in React Apps

React-bootstrap datepicker example; In this tutorial, i will guide you step by ste on how to integrate bootstrap datepicker in react js app using react-bootstrap 4.

React Bootstrap date picker is a plugin that adds the function of selecting time without the necessity of using custom JavaScript code. This documentation may contain syntax introduced in the MDB React.

How to Integrate Bootstrap DatePicker in React

  • Step 1 – Create React App
  • Step 2 – Install React Bootstrap
  • Step 3 – Create Bootstrap DatePicker Component
  • Step 4 – Import Bootstrap DatePicker Component in App.js

Step 1 – Create React App

Open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app my-react-app

To run the React app, execute the following command on your terminal:

npm start

Check out your React app on this URL: localhost:3000

Step 2 – Install React Bootstrap

Execute the following command to install react boostrap library into your react app:

npm install bootstrap --save

npm install react-bootstrap bootstrap

import bootstrap.min.css file in src/App.js file:

import React, { Component } from 'react'
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
function App() {
  return (
    <div>
      <h2>How to Create Bootstrap DatePicker in React</h2>
    </div>
  );
}
export default App;

Step 3 – Create Bootstrap DatePicker Component

Create BootstrapDatePickerComponent.js file. So, visit the src directory of your react js app and create a datepicker component file named BootstrapDatePickerComponent.js. And add the following code into it:

import React from 'react'
import { Form } from 'react-bootstrap';
class BootstrapDatePickerComponent extends React.Component{
    render(){
        return(
            <div>
                <div className="row">
                    <div className="col-md-4">
                        <Form.Group controlId="dob">
                            <Form.Label>Select Date</Form.Label>
                            <Form.Control type="date" name="dob" placeholder="Date of Birth" />
                        </Form.Group>
                    </div>
                </div>
            </div>
        )
    }
    
}
export default BootstrapDatePickerComponent;

Step 4 – Import Bootstrap DatePicker Component in App.js

import BootstrapDatePickerComponent.js file in src/App.js file:

import React from 'react';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import BootstrapDatePickerComponent from './BootstrapDatePickerComponent'
function App() {  
    
  return (  
    <div className="App">  
      <BootstrapDatePickerComponent />  
    </div>  
  );  
}  
export default App;

Conclusion

React-bootstrap datepicker example in-class component example; In this tutorial, you have learned how to integrate bootstrap datepicker in react js app using bootstrap 4 libraries.

Recommended React Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.