Creating React Components in PHP and then Rendering in the Client

I am trying to use React to simplify the way I create a UI for an application I am writing. I have a good proof of concept working on a single HTML page, but I need to split the JS into separate modules to make it easier to maintain.

I know how to structure an application if every piece of the puzzle is known at build time. Something like this: https://github.com/jordwalke/reactapp . However, the UI will be dynamically generated in PHP, embedding the various components that I want to pass into the application.

My initial thought of dumping the generated code into a script tag and having Javascript found that it was driving me into a terrible hell of a hell.

My main question:

How do I pass something like <panel><group><field /></group></panel>

to the application so that I can call it React.render()

?

+3


source to share


1 answer


As @llernestal and @MikeDriver suggested in the comments, I used PHP to generate a JSON representation of the UI and had React to build the components needed to render the UI.



+1


source







All Articles