From 0e2b4c1951ad7e0a115971eea83a07749c5da85e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julien=20Valverd=C3=A9?=
Loading user...
})) +``` + +Rules: + +- **Hook ordering**: place every React hook and effect-view hook helper *before* the first operation that may suspend. After a suspend point, the generator continuation runs outside React's synchronous render phase, so no hooks may follow it. +- The `promise` prop name is reserved on async components (used internally) — do not declare a prop with that name. + +When to reach for `Async` vs alternatives: + +- One-off asynchronous read before rendering → `Async.async`. +- Cached/shared/refreshable server reads → `Query` (see `Query.md`). +- User-triggered writes with pending/error state → `Mutation` (see `Mutation.md`). +- Async work in an event handler with no need for `Mutation` state → `useRunPromise`/`useCallbackPromise` (see `Component.md`). +- Subscriptions or background work tied to lifecycle → a scoped fiber forked from `useReactEffect`. + +## Memoized + +Wraps a component's rendered function with `React.memo`, so an unrelated parent re-render doesn't re-run the component (or restart an `Async` child's in-flight computation) when props are unchanged. + +```tsx +import { Async, Component, Memoized } from "effect-view" + +export const UserCard = Component.make("UserCard")(function* ({ userId }: { readonly userId: string }) { + const user = yield* Component.useOnChange(() => loadUser(userId), [userId]) + returnLoading...
:Not loaded.
, + onFailure: ({ cause, previousSuccess, waiting }) => (/* cause: Cause