Hi,
since Elixir variables are immutable the put_flash/3 in your first example doesn’t change your socket, but returns a new socket which you have to use.
In the second example you have to remove the socket from the put_flash. The pipe (|>) calls the next function with the return value of the previous one as first parameter automatically.
Your
socket |> put_flash(socket, :error, "Error!") is the same as
put_flash(socket, socket, :error, "Error!"), but you only want it once inside the call.
You could use either:
def handle_event("click", %{"content" => params}, socket) do
{:noreply, put_flash(socket, :error, "Error!")}
end
or
def handle_event("click", %{"content" => params}, socket) do
# This reassigns socket to the value returned by put_flash
socket =
socket
|> put_flash(:error, "Error!")
{:noreply, socket}
end






















