Skip to content

Instantly share code, notes, and snippets.

@antlis
Created April 16, 2026 20:16
Show Gist options
  • Select an option

  • Save antlis/764f333147afdd4bb175d610222db826 to your computer and use it in GitHub Desktop.

Select an option

Save antlis/764f333147afdd4bb175d610222db826 to your computer and use it in GitHub Desktop.
Safer wrapper around useAsyncData with sensible defaults to avoid duplicate requests and undefined state issues.
export function useAsyncDataSafe<T>(
key: string,
handler: () => Promise<T>
) {
return useAsyncData<T>(key, handler, {
server: true,
lazy: false,
default: () => null,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment