hemal's avatar
Level 1

React component not show in Laravel

my component like below

import React, { Component } from 'react';
import ReactDOM from 'react-dom';

export default class User extends Component {
    render() {
        return(
            <div className="container">
                <h2>
                    User Listing
                </h2>
                <table className="table table-bordered">
                    <tead>
                        <tr>
                            <th>Id</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Action</th>
                        </tr>
                    </tead>
                    <tbody>
                        <tr>
                            <td>1</td>
                            <td>adam</td>
                            <td>[email protected]</td>
                            <td>
                                <a href="" className="btn btn-primary">
                                    Edit
                                </a>
                                <a href="" className="btn btn-danger">
                                    Delete
                                </a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        );
    }
}
if (document.getElementById('user')) {
    ReactDOM.render(<User />, document.getElementById('user'));
}

and I have include that in blade file like below

<div id="user"></div>

but nothing show i have include component in app.js file what did I do wrong there is an error like below in console

Uncaught TypeError: Cannot read property 'Component' of undefined
    at Object.<anonymous> (app.js:53799)
    at __webpack_require__ (app.js:20)
    at Object.<anonymous> (app.js:10273)
    at __webpack_require__ (app.js:20)
    at Object.<anonymous> (app.js:10249)
    at __webpack_require__ (app.js:20)
    at validateFormat (app.js:63)
    at app.js:66
0 likes
2 replies
Robstar's avatar

Does extending React.Component work? Pretty sure your error has something to do with es7 transpiling. Thankfully I don;t do too much React lately, it's all Vue :)

cipa's avatar

Using defer fixed it for me

Please or to participate in this conversation.