Recently I was reviewing the code and in the HEEX template I noticed something like:
<tr
id={"#item-#{Phoenix.Param.to_param(item)}"}
...
We all knew that item
is the struct of the main resource we are dealing with on that view and I proposed to change the code to more simple and clear
<tr
id={"#item-#{item.id}"}
...
And overall I thought that we shouldn’t use Phoenix.Param.to_param/1
directly, not only in that context to fetch the param for the DOM element id but also anywhere else in our app code… like leave it to the framework and treat it as “undocumented feature”.
However, co-worker pointed me to generated CoreComponents.table/1
where he got the idea from.
While, I see that in the generic CoreComponent we need to be able to come up with an id for arbitrary input, I still don’t think it’s a right function for the job.
WDYT?