Reputation: 656
I tried to installLlaravel and scaffold ReactJs.
I have a problem in running my react component.
The installation was fine and Below is my first ReactJs component. However I cannot display the content of the react component.
components/Example.js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
export default class Example extends Component {
render() {
return (
<div className="container">
<div className="row justify-content-center">
<div className="col-md-8">
<div className="card">
<div className="card-header">Example Component</div>
<div className="card-body">I'm an example component!</div>
</div>
</div>
</div>
</div>
);
}
}
if (document.getElementById('example')) {
ReactDOM.render(<Example />, document.getElementById('example'));
}
Here is the file welcome.blade, inside the body
<div id="example"></div>
<script src="/js/app.js"></script>
It should display like this,
Example Component
I'm an example component!
Upvotes: 0
Views: 114
Reputation: 170
npm run dev
for development and npm run prod
for production on your laravel root directory Upvotes: 1