Is it possible to call a JS/React function from within an elixir file?

I have a JS library that I would like to use inside of an elixir file but I don’t know if there’s any way of having elixir use the functions from a JS/HTML file or am I simply dreaming?

You can shell out via System.cmd("node", args) but they’re complete different languages / platforms, so there’s no built in interop.

There are Phoenix channels to push events via a WebSocket. There’s RabbitMQ and other forms of Messaging & PubSub. There are NIFs and syscall tools like Rambo and Porcelain. And now with LiveView you can interoperate with JavaScript running in the browser.

https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html

Hopefully one of these techniques will work for you! :slight_smile:

1 Like

What sort of react code are you trying to use? Is it something that works as a static render (ssr) or is it dynamic that will require hydration.

I ask because I’ve been working on this for a while now when I have time: