lundi 4 décembre 2017

Laravel 5.5 render a React component in a blade view with data from the controller

My goals is to be able to do something like this in my blade view.

<Example name="$user->name" />

But this doesn't render anything.

When I do: <div id="example"></div>it renders the component without the props value which is normal.

So I am trying to pass data that came from my controller to my React component as a prop.

I am not sure if it's even possible.

This is my App.js:

require('./components/Example');

This is my Example.js component:

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

class Example extends Component {
    render() {
        return (
            <div className="container">
                <div className="row">
                    <div className="col-md-8 col-md-offset-2">
                        <div className="panel panel-default">
                            <div className="panel-heading">Example</div>

                            <div className="panel-body">
                                Hello, {this.props.name}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire