Use React in Laravel


Hi I am very new in laravel + react js. I wanna use react in laravel but i have problem Here is my problem

it is my app.js

    require('./bootstrap');


import React from 'react';
import  ReactDOM  from 'react-dom';
import Index from './components/Index';


if (document.getElementById('index')) {
    ReactDOM.render(<Index />, document.getElementById('index'));
}

and Index.js :

import React from 'react';
import ReactDOM from 'react-dom';

function Index() {
    return (
        <div className="container">
            <div className="row justify-content-center">
                <div className="col-md-8">
                    <div className="card">
                        <div className="card-header">Example</div>

                        <div className="card-body">example component!</div>
                    </div>
                </div>
            </div>
        </div>
    );
}

export default Index;

and this my blade :

<div id="index"></div>
<script type="text/javascript" src="../js/app.js"></script>

but Index component don not load

Source: React – Stack Overflow

September 3, 2021
Category : News
Tags: laravel | reactjs

Use React in Laravel


Hi I am very new in laravel + react js. I wanna use react in laravel but i have problem Here is my problem

it is my app.js

    require('./bootstrap');


import React from 'react';
import  ReactDOM  from 'react-dom';
import Index from './components/Index';


if (document.getElementById('index')) {
    ReactDOM.render(<Index />, document.getElementById('index'));
}

and Index.js :

import React from 'react';
import ReactDOM from 'react-dom';

function Index() {
    return (
        <div className="container">
            <div className="row justify-content-center">
                <div className="col-md-8">
                    <div className="card">
                        <div className="card-header">Example</div>

                        <div className="card-body">example component!</div>
                    </div>
                </div>
            </div>
        </div>
    );
}

export default Index;

and this my blade :

<div id="index"></div>
<script type="text/javascript" src="../js/app.js"></script>

but Index component don not load

Source: React – Stack Overflow

September 3, 2021
Category : News
Tags: laravel | reactjs

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.