Skip to content

Commit 615da44

Browse files
ryansolidClaude via Cursorcursoragent
committed
docs(h): lead with the render(h(App), el) rule
Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 5aee29c commit 615da44

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

‎packages/h/README.md‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@ h("div", { title: "My button" }, h("span", "1"), h("span", "2"), h("span", "3"))
1717

1818
This is the least efficient way to use Solid as it requires a slightly larger runtime that isn't treeshakeable, and cannot leverage anything in the way of analysis, so it requires manual wrapping of expressions and has a few other caveats (see below).
1919

20-
> `h(...)` returns a tagged zero-arity thunk rather than a DOM node directly;
21-
> calling it creates the element or component. Pass the thunk itself to
22-
> `render`: `render(h(App), el)` (with the JSX runtime, `render(<App />, el)`).
23-
> `render` calls it once inside the root. Do not wrap it as
24-
> `render(() => h(App), el)` or pass a component that returns an `h(...)`
25-
> thunk (`render(App, el)`): the uncalled thunk then reaches the renderer as a
26-
> reactive expression and is created again whenever its output changes — a
27-
> root `<Show>` is rebuilt on every toggle, and a root `<Loading>` over async
28-
> children never settles. Nested `h(...)` thunks, including those returned
29-
> from accessors like `() => (show() ? h(A) : h(B))`, are created once where
30-
> they are consumed, so composition with control-flow components like `<For>`
31-
> and `<Show>` works without extra wrapping.
20+
**Rendering:** `render(h(App), el)`.
21+
22+
`h(...)` already returns a thunk: `h(App)` is the equivalent of JSX's `() => <App />`, so pass it straight to `render`. Wrapping it again (`render(() => h(App), el)`) or passing a component that returns an `h(...)` thunk (`render(App, el)`) adds one function too many. The renderer then treats the inner thunk as a reactive expression and re-creates the component whenever its output changes: a root `<Show>` is rebuilt on every toggle, and a root `<Loading>` over async children never settles.
23+
24+
Nested `h(...)` thunks, including ones returned from accessors like `() => (show() ? h(A) : h(B))`, are created once where they are consumed, so composition with `<For>`, `<Show>` and other control flow needs no extra wrapping.
3225

3326
## Example
3427

0 commit comments

Comments
 (0)