'Displaying react js component in laravel 8 view doesn't work
I'm using laravel 8 for backend and react js for frontend . After the call of "app.js" in the view script "index.blade.php" to display "example" component, nothing is shown ... Here's my code :
Example.js
import React from 'react';
import ReactDOM from 'react-dom';
function Example() {
return (
<p>HEYYY THIS IS ME</p>
);
}
export default Example;
if (document.getElementById('example')) {
ReactDOM.render(<Example />, document.getElementById('example'));
}
index.blade.php :
@extends('layouts.app')
@section('content')
<div id="example">
<script src="{{ asset('js/app.js') }}"></script>
</div>
@endsection
web.php:
/* ... */
Route::get('/', function () {
return view('index');
})->where('/', '[^admin]*');
/* ... */
app.js :
require('./bootstrap');
require('./components/Example');
I think the call of app.js is correct because when i inspect it shows
<div id="example">
<script src="http://127.0.0.1:8000/js/app.js"></script>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
