phoenix_reactor v0.1.0 PhoenixReactor

Module contains a function which helps to render react component.

Summary

Functions

Renders react component container. It can be called in a phoenix template or directly in a phoenix view

Functions

react_container(name, props \\ %{}, html_attrs \\ [])

Specs

react_container(String.t | atom, map, Keyword.t) ::
  {:safe, list} |
  {:error, any}

Renders react component container. It can be called in a phoenix template or directly in a phoenix view.

Using in a template filex

...
<div>
  <%= PhoenixReactor.react_container("home", %{message: @message}) %>
<div>
...

Using in a view file

def render("show.html", assigns) do
  PhoenixReactor.react_container("home", assigns[:props])
end

Examples:

iex> PhoenixReactor.react_container("home") |> Phoenix.HTML.safe_to_string()
"<div data-react-component=\"home\" data-react-props=\"{}\"></div>"

iex> PhoenixReactor.react_container("home", %{your_message: "Hello World"}) |> Phoenix.HTML.safe_to_string()
"<div data-react-component=\"home\" data-react-props=\"{&quot;yourMessage&quot;:&quot;Hello World&quot;}\"></div>"

iex> PhoenixReactor.react_container("home", %{your_message: "Hello World"}, class: "container", id: "home") |> Phoenix.HTML.safe_to_string()
"<div class=\"container\" data-react-component=\"home\" data-react-props=\"{&quot;yourMessage&quot;:&quot;Hello World&quot;}\" id=\"home\"></div>"