{"id":14120,"date":"2023-04-20T18:24:04","date_gmt":"2023-04-20T18:24:04","guid":{"rendered":"http:\/\/43.205.139.175\/?p=14120"},"modified":"2023-04-28T10:29:28","modified_gmt":"2023-04-28T10:29:28","slug":"integrating-react-js-into-a-php-application","status":"publish","type":"post","link":"https:\/\/techvariable.com\/blogs\/integrating-react-js-into-a-php-application","title":{"rendered":"Integrating React.Js into a PHP application"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Use React.JS with Php<\/h2>\n\n\n\n<p>React (also known as React.js or ReactJS) is a JavaScript library for building user interfaces. It is maintained by Facebook and a community of individual developers and companies.<\/p>\n\n\n\n<p>React was created by Jordan Walke, a software engineer at Facebook. He was influenced by XHP, an HTML component framework for PHP. It was first deployed on Facebook\u2019s newsfeed in 2011 and later on Instagram.com in 2012. It was open-sourced at JSConf US in May 2013.<\/p>\n\n\n\n<p>Most developers choose to write React components in a JavaScript dialect known as JSX. It is essentially a mix of HTML and JavaScript. The tags need to be closed and there are some differences like using the attribute className instead of just class for defining CSS classes. JSX is transformed into JavaScript for manipulating the DOM.<\/p>\n\n\n\n<p>For example JSX:<br>var HelloMessage = React.createClass({<br>render: function() {<br>return<br>Hello {this.props.name}<br>;<br>}<br>});<br>ReactDOM.render(, mountNode);<br>is transformed to JavaScript by a JSX parser:<br>\u201cuse strict\u201d;<br>var HelloMessage = React.createClass({<br>displayName: \u201cHelloMessage\u201d,<br>render: function render() {<br>return React.createElement(<br>\u201cdiv\u201d,<br>null,<br>\u201cHello \u201c,<br>this.props.name<br>);<br>}<br>});<br>ReactDOM.render(React.createElement(<br>HelloMessage, { name: \u201cJohn\u201d }<br>), mountNode;<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Now can we use React js with Php ?<\/h5>\n\n\n\n<p>Yes. This is possible. Reactjs is just the \u2018V\u2019 in MVC. React doesn\u2019t care what you are using at backend. One can render React\u2019s components on server side in PHP using V8Js PHP extension, but this is not necessary. Server side rendering in Reactjs is optional. Here are some things you can do:<br>1.Compile your whole reactjs JSX code using babel. It would be better if you make use of some module bundler like webpack and compile your reactjs code into a single file. Upload that single file on your server.<br>2.You can populate default states in your react code using php.<br>The best way to use PHP as backend with React Js as front end is to keep both seperate. Make a stand alone front-end and use PHP to create APIs which interacts with the database. Then consume the API through HTTP AJAX or whatever mechanism React Js contains.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use React.JS with Php React (also known as React.js or ReactJS) is a JavaScript library for building user interfaces. It is maintained by Facebook and a community of individual developers and companies. React was created by Jordan Walke, a software engineer at Facebook. He was influenced by XHP, an HTML component framework for PHP. It [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"h5ap_radio_sources":[],"footnotes":""},"categories":[8,12],"tags":[],"class_list":["post-14120","post","type-post","status-publish","format-standard","hentry","category-blogs","category-development-and-design"],"acf":[],"_links":{"self":[{"href":"https:\/\/techvariable.com\/index.php?rest_route=\/wp\/v2\/posts\/14120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvariable.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvariable.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvariable.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvariable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14120"}],"version-history":[{"count":0,"href":"https:\/\/techvariable.com\/index.php?rest_route=\/wp\/v2\/posts\/14120\/revisions"}],"wp:attachment":[{"href":"https:\/\/techvariable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvariable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvariable.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}