MRdotB

MRdotB

I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live_vue and live_svelte. So, I created the equivalent in React, live_react:

https://github.com/mrdotb/live_react

Here is a small demo on Fly: demo.

I have not yet implemented SSR, slots, sigil, and the macro to generate components.

Showing Posts 1 to 8

johnknott

johnknott

Great work! I do wonder if there is some kind of shared abstraction these libraries could build on - if there was something like live_vite or live_frontend, or something like that, then have adaptors for each FE framework.

MRdotB

MRdotB OP

The LOC of each library is quite short but specific to Vite, Svelte, React.

Builder JS Prod
live_svelte Custom esbuild none
live_vue vite vue
live_react hex esbuild react, react-dom

Have a look at the hooks.js of each
https://github.com/Valian/live_vue/blob/main/assets/js/live_vue/hooks.js
https://github.com/woutdp/live_svelte/blob/master/assets/js/live_svelte/hooks.js
https://github.com/mrdotb/live_react/blob/main/assets/js/live_react/hooks.js

orion

orion

Great work! Thank you for live_react!

I’m not sure if it’s what @johnknott had in mind but have you looked at Komodo?

MRdotB

MRdotB OP

live_react has been picking up interest, as seen in projects like PhoenixAnalytics. Inspired by the Server-Side Rendering (SSR) features in live_svelte and live_vue, I’ve implemented it for live_react.

I released a 0.2.0-beta and will release 0.2.0 when I’m confident the SSR feature is production ready.

ssr demo

MRdotB

MRdotB OP

I released the stable v1.0.0
I have been using live_react in production for different project.

Breaking Changes:

  • vitejs: switch from Mix Esbuild to Vite.js

Features:

  • add tests based on the one from live_vue
  • add SSR support
  • support inner_block slot
  • context provider for live_react
  • add typescript support
Temples-Dev

Temples-Dev

Hello, I am new to the Elixir community, i think you have a great project. I went through the live example in the github project,i was hoping to find JSX related syntax in the example but i did not. i don’t know if its in there somewhere. which kept me wondering how does live_react workings like react itself. I will appreciate clarification. Also i want to suggest that it will be nice to have the configuration scaffold with a command to get everything setup instead on following the installation guide with a lot of configs. it makes its quiet easy to setup for use. thank you.

MRdotB

MRdotB OP

Hi! Welcome to the Elixir community, and thanks for your interest!

LiveReact isn’t a full React framework like inertia-phoenix —it lets you render React components inside LiveView / DeadView, not replace it. You can check out the demo to see it in action.

For internals, the source code is short and worth reading.

Regarding scaffolding

There’s already a Mix task to help with setup—see the [installation guide]

MRdotB

MRdotB OP

I released v2.0.0.

Almost everything in this release is a port of work that already existed in
live_vue - props diffing, stream support and
the encoder protocol. Claude did the bulk of the porting.
Big thanks to @Valian

Breaking Changes:

  • data-props is now encoded through the new LiveReact.Encoder protocol instead of
    Jason.Encoder. Structs passed as props need @derive LiveReact.Encoder (or an
    explicit implementation); plain maps are unaffected. See
    Upgrading to 2.0.

Features:

  • Props are diffed and sent incrementally over data-props-diff instead of the full
    props being re-sent on every update. On by default
    (config :live_react, enable_props_diff: true), opt out globally with false or per
    component with diff={false}.
  • Phoenix.LiveView.stream/4 assigns are supported: a stream passed as a prop is diffed
    and delivered over data-streams-diff, arriving on the client as an array whose items
    carry their __dom_id.
  • LiveReact.Encoder ships implementations for the structs you are most likely to pass
    as props: Phoenix.HTML.Form (including Ecto changeset values and errors),
    Phoenix.LiveView.AsyncResult, Phoenix.LiveView.UploadConfig,
    Phoenix.LiveView.UploadEntry, and Date, Time, NaiveDateTime and DateTime.

New guide: Props Diffing and Streams.

New examples site:

The demo app moved out of the library into its own repository and now lives at
https://live-react.mrdotb.com. Every example has Preview / LiveView / React tabs,
so you can read the server side and the client side of the same page side by side.

The 2.0 features have examples of their own:

  • props-diffing — only the changed
    prop path travels over the wire, unless a component opts out
  • streams — insert, replace, edit, delete
  • encoder — what @derive LiveReact.Encoder
    sends to the client, and what it keeps on the server
  • asyncassign_async’s AsyncResult
    reaching React as loading, ok and failed
— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
pferriby
Introductory paragraph I’ll be looking for a keen junior or someone that has a couple of years experience in the real world (so you’ve be...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews