Elixir Blog Post: Passing Unknown Attributes into Your Component

On your LiveView page, you are using a custom component. You want to be able to pass HTML attributes into the component, but the component doesn’t know anything about the attributes being passed! You need a way to pass arbitrary attributes through and get them where you want them.

I use lots of stateless LiveView components in my projects. A tip I learned makes it easier to keep components generic and reusable. Now written up as a recipe!


Great post! I didn’t know about assigns_to_attributes/2!

We wrote a lot of live and stateless components and extracted some functions that helped us to make components extensible & reusable into a library:

1 Like