Assings mapping on Phoenix.Component

Hi all!

I’m having problems to understand how the assigns mapping works on components. I haven’t found anything here. I have a form defined at <name>_form.html.heex (as it is created with the generator phx.gen.context). Now I would like to add to this form a selector with options coming from another model, on the controller I copied the data to conn.assigns.categories but I can access the data using @categories on the form at <name>_form.html.heex, even though I can do it on the new.html.heex. Therefore I believe I have an issue with the “attrs” used to map variables to the form’s assigns. Any idea how this process works? I tried adding attr: :categories, :list also attr: :categories, :any and also on the controller with render(conn, :new, %{changeset: changeset, categories: conn.assigns.categories}) with no luck :frowning:

How do I send a particular data from my controller to a component? Thanks!!

You don’t – at least not directly. render/3 in the controller passes the assigns data to the :new component, which is defined by the new.html.heex template. In there you need to explicitly pass any assigns to nested function components, if they require access to those values. Data is not implicitly shared.

You are right, now I feel dumb :sweat_smile: I got lost on the back and forth of the controller with the view hahahahahah

thanks! :slight_smile: