Keep spacing consistent between elements when text is changed (e.g. a button group)

Is there anything like auto-layout in Figma where objects will auto-resize and maintain spacing between if you change the text?

I want to create a duo-button component (primary button next to secondary button), so that when I replace the text with things like “Save/Cancel” or “Next/Back” the buttons will maintain 8px between.

I believe repeater widgets can do this, but it needs to be the same component I think? (I can’t use a primary button in one column and a secondary button in another)

I don’t know javascript, but maybe there’s a string I can use to say if primary button resizes X amount push secondary button that same amount?

When is the text changing? When you’re editing the project file or when it’s being previewed?

The logic approach you suggested is possible but only in preview mode. If you’re changing the text when you’re editing, it’s probably just easier to move and align the buttons manually.