PHP with React JS - Combined
By: Luis A. Sierra
React is the library for web and native user interfaces. Build user interfaces out of individual pieces called components written in JavaScript.
Getting Started:
<html lang="en">
<meta charset="utf-8">
<title>Title Here</title>
<body>
<h1>Content Heading</h1>
<p>Content paragraph</p>
</body>
</html>
Output:
<html lang="en">
<title>Test React</title>
<script src= "https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script src= "https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<body>
<div id="root"></div>
<script type="text/babel">
const name = 'Luis A. Sierra';
function Welcome() {
return <h1>Hello {name}</h1>;
}
ReactDOM.render(<Welcome />, document.getElementById('root'));
</script>
</body>
</html>
Output:
Adding React to an PHP Page:
<html lang="en">
<title>Test React</title>
<script src= "https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script src= "https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<body>
<div id="root"></div>
<script type="text/babel">
const name = 'Luis A. <?php echo $last_name; ?>';
function Welcome() {
return <h1>Hello {name}</h1>;
}
ReactDOM.render(<Welcome />, document.getElementById('root'));
</script>
</body>
</html>
Post a Comment