I am unsure why you are doing this if you are using inertia. Inertia is for spa
if (document.getElementById('user-details')) {
ReactDOM.render(<UserDetails/>, document.getElementById('user-details'));
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi Everyone,
I have installed the Breeze + React starter pack following the docs.
In my Dashboard.jsx I imported a custom component I made, rendered fine.
Problem is, now I am trying to make that custom component display data retrieved from a controller, but so far I'm running into problems.
Currently I have:
app/Http/Controllers/UserDetailsController.php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Inertia\Inertia;
use App\Models\User;
class UserDetailsController extends Controller
{
/**
* Return all users.
*
* @return \Inertia\Response
*/
public function __invoke()
{
return Inertia::render('UserDetails', [
'users' => User::all(),
]);
}
}
resources/js/Pages/Dashboard.jsx
import React from 'react';
import Authenticated from '@/Layouts/Authenticated';
import { Head } from '@inertiajs/inertia-react';
import UserDetails from '@/Components/UserDetails';
export default function Dashboard(props) {
return (
<Authenticated
auth={props.auth}
errors={props.errors}
header={<h2 className="font-semibold text-xl text-gray-800 leading-tight">Dashboard</h2>}
>
<Head title="Dashboard" />
<div className="py-12">
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div className="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div className="p-6 bg-white border-b border-gray-200">You're logged in!</div>
<div className="p-6 bg-white border-b border-gray-200" id="user-details"></div>
</div>
</div>
</div>
</Authenticated>
);
}
resources/js/Components/UserDetails.jsx
import React from 'react';
import ReactDOM from 'react-dom';
export default function UserDetails({userdetails}) {
return (
<div className="container">
<div className="row justify-content-center">
<div className="col-md-8">
<div className="card">
<div className="card-header">Users header</div>
<ul>
{Object.keys(userdetails).map(function (key, index) {
return <li key={index}>{userdetails[key]}</li>;
})}
</ul>
<div className="card-body">Card body</div>
</div>
</div>
</div>
</div>
);
}
if (document.getElementById('user-details')) {
ReactDOM.render(<UserDetails/>, document.getElementById('user-details'));
}
The Dashboard page is not rendering with that setup (the component renders on the dashboard fine with just plain markup). Dev tools is throwing an error: "UserDetails.jsx:12 Uncaught TypeError: Cannot convert undefined or null to object"
What am I missing? Need to set up a route certain way?
Thanks for help in advance
If you want to leave out the word props, you can extract your props
export default function UserDashboard({auth, errors, message}) {
Please or to participate in this conversation.