I'm a complete novice with REACT, especially to extract information from the server. I don't have any API inside my backend, so... Can I generate react code as follow?
Example of my component:
var Test= React.createClass({
render: function () {
return (
<div>
<p>
This is my test: {this.props.name}
</p>
</div>
);
}
});
How I think I can "render" this react component with a PHP Loop:
<script type="text/babel">
<?php foreach($tests as $test){ ?>
ReactDOM.render(
<div className="text-center">
<Test name="Test 1" />
<Test name="laralala" />
</div>
,document.getElementById("test")
);
<?php} ?>
</script>
But I think the previous "way" it's a complete bad practice... Can someone help me a little? My intention is not to have to change anything in the backend ...
Thank you very much.
var test = <?php echo json_encode($tests); ?>;???$testswas updated (by a form for example). This kinda goes agains all this "single page application" logic. But I guess if you do not have an API, you're stuck with this solution.