gdub01

gdub01

My experience w/ react & phoenix on my side project

Hey guys - I just finished my side project - misheneye.com (creates brand guides) - recently and used an spa - react (nextjs.org flavor). Wanted to share some thoughts..

Advantages

I was able to use react’s ecosystem. I chose material-ui.com for the ui, which saved quite a bit of work. The user gets decent default behavior that works across browsers.

Apollo is the client side consumer of absinthe’s graphql api and provides great caching options. You’re able to store fetched data on the client side and have fine grained control over updates of that data.

As the user switches pages, the graphql queries needed to support that page/view fetch from cache first, only falling back to the network if necessary. So navigation is quick, and there’s less load on the server/lookups from the db.

Disadvantages

Missed out on some of the advantage of phx generators.

Hit issues with react code that should be client-side only instead of SSR/statically generated.

Had to google for syntax switching back and forth from elixir to react.

Spent more time on devops + configuration.

Neutral

Phoenix obviously :smile: delivers server side rendered html by default. Nextjs allows you to compile/export your react app as static HTML files, or SSR it. I chose static so it’s just hosted by phoenix for now. The static content makes it SEO friendly… but I know I could SSR it at a later date to get the same SEO benefit, for more user-generated content.

Overall

Due to aggressive client-side caching, it’s slightly more efficient with the spa for data fetching because it fetches data less frequently… but there’s a larger javascript bundle for the client to download initially. So :man_shrugging: . Developing, however, took more time.

Were I to do it again now, I’d work harder to see if the SPA was truly required before going down that route to save quite a bit of time.

Also, gotta say, I love this community and the ecosystem. Absinthe with dataloader is great, as is phoenix and elixir itself… and really all the packages I’ve used. So thanks guys =)

First Post! Switch mode

mbuhot

mbuhot

Thanks for sharing your experience!

What would the key criteria be for you to confidently use a SPA architecture again?

Most Liked

gdub01

gdub01

Good question! After thinking about it, I’d say:

1 offline support
2 large-traffic site that can use client-side caching to meaningfully reduce server load/cost
3 cross-browser support for complex ui components
4 building out clients for web and mobile apps simultaneously (ala react native for web, or perhaps flutter for web)

The first 3 things can totally be solved without an SPA too… but I think after a certain amount of JS additions, managing JS without an SPA can be worse than with an SPA.

The 4th item works if you know up front you’ll need ios, android and web clients, and you don’t need too many platform-specific features. In that case, I think it can be faster to use an SPA. A frontend developer can make changes across all three platforms in the same language… and there would be quite a bit of code reuse around data fetching and other things. I’ve often heard about 80% code reuse.

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2976 91332 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
zachdaniel
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses: I had hope...
New

We're in Beta

About us Mission Statement