create simple react website example – onlinecode

create simple react website example – onlinecode

In this post we will give you information about create simple react website example – onlinecode. Hear we will give you detail about create simple react website example – onlinecodeAnd how to use it also give you demo for it if it is necessary.

In this article, we would like to inform you that how to create simple react website example. ReactJs is an open-source JavaScript library and it is developed by Facebook. react js can be used to make a single-page application(SPA). ReactJS is also used to reuse UI components and run without reloading application so it is scalable, simple, and fast.

So, you can follow the below steps for create simple react website example.

Step 1: Install React Application

In this step, if you want to create a react application then you can follow below Url for install react js.

npx create-react-app my-website
cd my-website

Step 2: Install bootstrap in react

now, After the installation of react js, you can install the bootstrap using the below command.

npm install bootstrap --save

here, we will import the bootstrap in the app.js file, so you can see the below code.src/app.js

import React, { Component } from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';

class App extends Component {
  render() {
    return (
      <div className="container">
        <h2>React CRUD Tutorial</h2>
      </div>
    );
  }
}

export default App;

Step 3: Configure React routing

The below command using install the react route. so you can follow the below command.

npm install react-router-dom --save

Go to the index.js file and Modify the below code.src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';

import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
  <BrowserRouter>
  <App />
  </BrowserRouter>, document.getElementById('root'));

serviceWorker.unregister();

Step 4: Create react components

here in this step, we will create three components, like home, about, and contact. so you can see the below code.src/home.component.js

import React, { Component } from 'react';

export default class Home extends Component {
    render() {
        return (
            <div >
            <h3>Welcome To Home Page</h3>
            <b>Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups</b></p>
            Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
            Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
            <b>Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups</b></p>
            Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
            Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
            <b>Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups</b></p>
            Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
            Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
        </div>
        )
    }
}

src/about.component.js

import React, { Component } from 'react';

export default class About extends Component {
    render() {
        return (
            <div >
                <h3>Welcome To About Page</h3>
                <b>Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups</b></p>
                Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
                Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
                <b>Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups</b></p>
                Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
                Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
                <b>Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups</b></p>
                Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
                Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
            </div>
        )
    }
}

src/contact.component.js

import React, { Component } from 'react';

export default class Contact extends Component {
    constructor() {
        super();
        this.state = {
          fields: {},
          errors: {}
        }
  
        this.handleChange = this.handleChange.bind(this);
        this.submitContactForm = this.submitContactForm.bind(this);
  
    };


    handleChange(e) {
    let fields = this.state.fields;
    fields[e.target.name] = e.target.value;
    this.setState({
        fields
    });

    }
  
    submitContactForm(e) {
        e.preventDefault();
        if (this.validateForm()) {
            let fields = {};
            fields["txtFname"] = "";
            fields["txtLname"] = "";
            fields["txtEmail"] = "";
            fields["txtMessage"] = "";
            this.setState({fields:fields});
            alert("Form submitted");
        }

    }
  
    validateForm() {
        let fields = this.state.fields;
        let errors = {};
        let formIsValid = true;

        if (!fields["txtFname"]) {
            formIsValid = false;
            errors["txtFname"] = "Please Enter Your First Name.";
        }

        if (typeof fields["txtFname"] !== "undefined") {
            if (!fields["txtFname"].match(/^[a-zA-Z ]*$/)) {
            formIsValid = false;
            errors["txtFname"] = "Please Enter Alphabet Characters Only.";
            }
        }


        if (!fields["txtLname"]) {
            formIsValid = false;
            errors["txtLname"] = "Please Enter Your Last Name.";
        }

        if (typeof fields["txtLname"] !== "undefined") {
            if (!fields["txtLname"].match(/^[a-zA-Z ]*$/)) {
            formIsValid = false;
            errors["txtLname"] = "Please Enter Alphabet Characters Only.";
            }
        }

        if (!fields["txtEmail"]) {
            formIsValid = false;
            errors["txtEmail"] = "Please Enter Your Email.";
        }

        if (typeof fields["txtEmail"] !== "undefined") {
            //regular expression for email validation
            var pattern = new RegExp(/^(("[w-s]+")|([w-]+(?:.[w-]+)*)|("[w-s]+")([w-]+(?:.[w-]+)*))(@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$)|(@[?((25[0-5].|2[0-4][0-9].|1[0-9]{2}.|[0-9]{1,2}.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}).){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})]?$)/i);
            if (!pattern.test(fields["txtEmail"])) {
            formIsValid = false;
            errors["txtEmail"] = "Please Enter Valid Email.";
            }
        }


        if (!fields["txtMessage"]) {
            formIsValid = false;
            errors["txtMessage"] = "Please Enter Your Message.";
        }
		
        this.setState({
            errors: errors
        });
        return formIsValid;
    }  
    render() {
        return (
            <div >
                <form  method="post"  name="contactform" onSubmit= {this.submitContactForm}>
                    <div >
                        <label  for="txtFname">First Name:</label>
                        <div >
                            <input type="text"  id="txtFname" placeholder="Enter First Name" name="txtFname" onChange={this.handleChange}/>
                            <div className="errorMsg">{this.state.errors.txtFname}</div>
                        </div>
                    </div>
                    <div >
                        <label  for="txtLname">Last Name:</label>
                        <div >
                            <input type="text"  id="txtLname" placeholder="Enter Last Name" name="txtLname" onChange={this.handleChange}/>
                            <div className="errorMsg">{this.state.errors.txtLname}</div>
                        </div>
                    </div>
                    <div >
                        <label  for="txtEmail">Email:</label>
                        <div >
                            <input type="email"  id="txtEmail" placeholder="Enter Email" name="txtEmail" onChange={this.handleChange}/>
                            <div className="errorMsg">{this.state.errors.txtEmail}</div>
                        </div>
                    </div>
                    <div >
                        <label  for="txtMessage">Message:</label>
                        <div >
                            <pre name="txtMessage"  id="txtMessage" onChange={this.handleChange}></pre>
                            <div className="errorMsg">{this.state.errors.txtMessage}</div>
                        </div>
                    </div>
                    <div >        
                        <div >
                            <button type="submit" >Submit</button>
                        </div>
                    </div>
                </form>
            </div>
        )
    }
}

Step 5: Set up the route inside the App.js

now, we load the header menu and set up the route inside the App.js file.src/App.js

import React, { Component } from 'react';
import { BrowserRouter as Router, Switch, Route, NavLink } from 'react-router-dom';

import home from './home.component';
import contact from './contact.component';
import about from './about.component';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  render() {
    return (
      <Router>
        <nav >
          <div >
            <div >
              <button type="button"  data-toggle="collapse" data-target="#myNavbar">
                <span ></span>
                <span ></span>
                <span ></span>                        
              </button>
              <a  href="https://speedassessment.com/?big=#"><img src={logo} className="App-logo" alt="logo" /></a>
            </div>
            <div  id="myNavbar">
              <ul >
                <li><NavLink exact activeClassName="active" to={'/'}>Home</NavLink></li>
                <li><NavLink activeClassName="active" to={'/about'}>About</NavLink></li>
                <li><NavLink activeClassName="active" to={'/contact'}>Contact</NavLink></li>
              </ul>
            </div>
          </div>
        </nav>
        <Switch>
            <Route exact path='/' component={ home } />
            <Route path='/about' component={ about } />
            <Route path='/contact' component={ contact } />
        </Switch>
      </Router>
    );
  }
}
export default App;

Step 6: Run React js application

If you want to run the application then you can follow the below command. if you any change in your app then use the npm run build and after you can run the application.

cd my-app
npm start

Now we will run our application using the below Url in the browser.

http://127.0.0.1:3000

Please follow and like us:

Hope this code and post will helped you for implement create simple react website example – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github