Created
October 15, 2025 06:21
-
-
Save sergiodxa/eaedf5bfdbcecee381e3d09688bcddfd to your computer and use it in GitHub Desktop.
An example on how to use `this.queueTask` to run something on every render or on mount
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
import type { Remix } from "@remix-run/dom"; | |
import { press } from "@remix-run/events/press"; | |
function Component(this: Remix.Handle) { | |
let isMounted = false; | |
let renderCount = 0; | |
// Runs once after first render (setup phase) | |
this.queueTask(() => { | |
isMounted = true; | |
this.update(); | |
}); | |
return () => { | |
// Runs after every render (render phase) | |
this.queueTask(() => void renderCount++); | |
return ( | |
<div> | |
<p>Is mounted: {isMounted ? "Yes" : "No"}</p> | |
<p>Render count: {renderCount}</p> | |
<button on={[press(() => this.update())]}>Trigger Re-render</button> | |
</div> | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment