Skip to content

Commit c6d069a

Browse files
committed
Improve <Show> reference
1 parent d5c820e commit c6d069a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/routes/reference/components/show.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ function Example() {
2626

2727
## Keyed rendering
2828

29-
When the `keyed` prop is set to `true`, the children of the `<Show>` component are re-rendered every time the `when` prop changes.
30-
It's important to note that in this case, even if the reference of the `when` prop changes, the children will still re-render.
29+
When the `keyed` prop is set to `true`, changes to the `when` prop—including reference changes—trigger a re-render of the `<Show>` component’s children.
3130

3231
```tsx
3332
import { createSignal, Show } from "solid-js";
@@ -59,11 +58,11 @@ The `<Show>` component can also accept a render function as its child.
5958
In this case, the first argument of the render function is an _accessor_ to the `when` prop.
6059
However, when the `keyed` prop is set to `true`, the argument is the `when` prop itself instead of an accessor.
6160

62-
The render function is treated like a separate component.
63-
A key point to understand is that the render function is wrapped in [`untrack`](/reference/reactive-utilities/untrack).
64-
As a result, any changes to signals accessed directly within the render function will not trigger updates.
61+
When a render function is used, it is internally wrapped with [`untrack`](/reference/reactive-utilities/untrack).
62+
As a result, signals accessed directly within the render function's scope will not react to updates.
6563

66-
For example, in the following code, clicking the increment button does not update the count value displayed on the screen because the `count` signal is not tracked.
64+
For example, in the following code, the count displayed in the first `<Show>` component does not update when the `count` signal changes.
65+
However, the second `<Show>` component does update since the `count` signal is accessed within a JSX element, which creates a tracking scope.
6766

6867
```tsx
6968
import { createSignal, Show } from "solid-js";
@@ -73,9 +72,9 @@ function RenderFunctionExample() {
7372
return (
7473
<div>
7574
<button onClick={() => setCount((c) => c + 1)}>Increment</button>
76-
{/* This does not update because the count signal is not being tracked. */}
75+
{/* This does not update. */}
7776
<Show when={count()}>{(c) => count()}</Show>
78-
{/* This will update because the outer JSX element creates a tracking scope. */}
77+
{/* This will update. */}
7978
<Show when={count()}>{(c) => <>{count()}</>}</Show>
8079
</div>
8180
);

0 commit comments

Comments
 (0)