DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Scott Barrow
Scott Barrow

Posted on • Updated on

self-referential data-reflex-root

It can sometimes be tricky to re-render an element, partial or view component in a selector morph from a reflex, especially if it needs new.

An alternative approach to selector morphs is wrapping your element(s) in a div with data-reflex-root. The value of the data attr will be used as the selector(s) for the morph.
A neat trick is that you can do this on itself

<div id="unique-morph-target" data-controller='resource-toggle-component' data-reflex-root='#unique-morph-target'>
Enter fullscreen mode Exit fullscreen mode

N.b. only the children of this element will be morphed, and not the element itself!
One major difference is that this approach still hits the controllers original action, which may or may not be desirable.
There’s nothing special needed in the reflex
ref: https://docs.stimulusreflex.com/morph-modes#scoping-page-morphs

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›