0

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!

2
  • 2
    Got any errors in your developer tools? Did you run npm run dev? Commented Aug 2, 2019 at 7:16
  • This problem was 3 months ago, and was resolved. Thanks for the help. Commented Nov 26, 2019 at 15:35

1 Answer 1

1
  1. install nodejs and npm
  2. run npm run dev for development and npm run prod for production on your laravel root directory
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.