!!! note This post is a thought. It's a short note that I make about someone else's content online. Learn more about the process here

Here's my thought on 💭 </> htmx ~ The response-targets Extension

The htmx response-targets extension allows me to respond to errors from the backend and do normal htmx swaps.

!!! note by default htmx will only swap on 200 and 300 responses

Load the extension in head

<script src="https://unpkg.com/[email protected]/dist/ext/response-targets.js"></script>

Use the extension on an endpoint that might return a 400.

<div hx-ext="response-targets">
    <div id="response-div"></div>
    <button hx-post="/register"
    <div id="serious-errors"></div>
    <div id="not-found"></div>

This post was a thought by Waylon Walker see all my thoughts at https://waylonwalker.com/thoughts