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'>
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)