I am having issues trying to render my React component within my 'login' view. I am using the Laravel Framework. The page is loaded, however I find no React component in my React Devtools. The Example component provided in the Laravel Project template renders fine. I could not find an error in my syntax, and I was hoping one of you could help me find my error.
My login.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel Login</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@200;600&display=swap" rel="stylesheet">
<link href="{{ URL::asset('public/css/app.css') }}">
</head>
<body>
<div id="login-form">
</div>
<script defer src='./js/app.js'> </script>
</body>
</html>
My LoginForm.js
import React from 'react';
import ReactDOM from 'react-dom';
function LoginForm() {
return (
<div class= "container">
Insert FORM here TEST
</div>
);
}
export default LoginForm;
if (document.getElementById('login-form')) {
ReactDOM.render(<LoginForm />, document.getElementById('login-form'));
}
My web.php
<?php
use IlluminateSupportFacadesRoute;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/login', function () {
return view('login');
});
My app.js
require('./bootstrap');
require('./components/Example');
require('./components/LoginForm');
question from:https://stackoverflow.com/questions/66056411/problem-trying-to-render-react-component-in-laravel-project