3

I need pass data in blade to react component. I use laravel 5.6.
For example in simple react component pass data via 'props' and i don't find method in laravel documentation to pass. I've tried (blade):

<Preview article={{ $article }}></Preview>

React:

constructor(props){
  super();
  this.state={
    article: props.article
  }
}

render() {
  return (
    <div>
      <h2>{this.state.article}</h2>
      <h3>Net</h3>
    </div>
  );
}

How can i do it in Laravel? In advance thanks for help.

2
  • Can you please show more code? Your entire view and react component would be better to see what you're trying to do. Commented Jul 11, 2018 at 14:42
  • i need just pass data. Not understanding why you need code :) Okey. Source code: pastebin.com/NDE1Qq5b I tried so and not working Commented Jul 11, 2018 at 15:13

2 Answers 2

2

Use this :

{!! $article !!}

instead of this :

{{ $article }}
Sign up to request clarification or add additional context in comments.

1 Comment

such way don't work in laravel. I think need something composer package or other way
1

To pass data from blade to react, simply use let in your blade view.

Change your view to something like this

// Use react to display article
<Preview article={article}></Preview>

// Pass data to react
<script>
      let Article= '{{ $article }}'
</script>

1 Comment

Unfortunately does not work. Did I do it right? pastebin.com/DQLyy3j7 Help me please.

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.