Created
September 19, 2024 16:21
-
-
Save KonnorRogers/20eede8c2dfbfa807bf0d6c7c39c1c1a to your computer and use it in GitHub Desktop.
Refresh button for Turbo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button type="button" data-controller="refresh">Refresh</button> | |
<script type="module"> | |
import { Controller } from "@hotwired/stimulus" | |
export default class RefreshController extends Controller { | |
connect () { | |
this.element.addEventListener("click", this.sendRefresh) | |
} | |
sendRefresh = () => { | |
const refreshStream = document.createElement("turbo-stream") | |
refreshStream.setAttribute("action", "refresh") | |
document.body.append(refreshStream) | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment