Server side rendering - do I need react?

In my experience, if you are going to write your client-side code in React then you really don’t end up using the templates and views in Phoenix very much. You are much better off, in my experience, simply using Phoenix to provide an back-end API and just writing your front end, in React, to use that API.

The sticking point I’ve run into involves getting values from the “Elixir world” of .eex templates into the JavaScript world of the encapsulated JavaScript modules where your React components live.

Using something like webpack, it is possible to set up a system that loads individual JavaScripts on a per-Phoenix-View basis… but the solutions I’ve seen, or have created, seem very ad-hoc and require more discipline, rigor, and understanding on the part of the developer than I personally prefer.

I’ve had success using Elm, and React with Phoenix, but I’ve really found a good way to mix either of them with Phoenix Templates and .eex (apart from perhaps embedding individual components in .eex here or there).

YMMV

3 Likes