mardi 22 octobre 2019

how to run laravel and reactjs app on localhost(xampp)

I have an I am building with reactjs and laravel 5.8 on my localhost(xampp) but I am seeing a blank page.

I did npm run dev on my terminal and refreshed the page but nothing happened.

resources/js/app.js

require('./bootstrap');
require('./components/Example');

resources/views/home.blade.php

 <!DOCTYPE html>
 <html lang="">
 <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Laravel</title>
    <link rel="stylesheet" href="css/app.css">
    <div id="example"></div>
    <script src="/js/app.js"></script>
  </body>

resources/js/components/Example.js

import React from 'react';
import ReactDOM from 'react-dom';

 function Example() {
  return (
    <div className="container">
        <div className="row justify-content-center">
            <div className="col-md-8">
                <div className="card">
                    <div className="card-header">I got it right</div>
                    <div className="card-body">I'm an example component!</div>
                </div>
            </div>
        </div>
    </div>
   );
  }

 export default Example;

if (document.getElementById('example')) {
  ReactDOM.render(<Example />, document.getElementById('example'));
}

I want it display the component for me on the page. Any help?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire