In live view I am loading some data in mount/3, I want to then access this data later on in handle_event however I am not sure how to share it, do I put it on the session, the connection, or something else?
mount/3
handle_event
I feel I am missing something obvious. Thanks.
You keep your state in socket.assigns:
def mount(_params, _session, socket) do {:ok, assign(socket, :my_data, [1, 2, 3])} end def handle_event("some-event", _payload, socket) do IO.inspecdt({:my_data, socket.assigns.my_data}) {:noreply, socket} end
Thanks for the answer, just what I needed. I realised I needed to also pass this data through to form components which got it working for me.