You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/routes/reference/components/show.mdx
+72-31Lines changed: 72 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -3,48 +3,89 @@ title: <Show>
3
3
order: 5
4
4
---
5
5
6
-
The `Show` control flow is used to conditionally render part of the view: it renders children when `when` is truthy, a fallback otherwise. It is similar to the ternary operator `(when ? children : fallback)` but is ideal for templating JSX.
// This operation changes the reference of the user object.
40
+
setUser({ ...user() });
41
+
}
42
+
43
+
return (
44
+
<div>
45
+
<buttononClick={update}>Update</button>
46
+
<Showwhen={user()}keyed>
47
+
<p>Name: {user().name}</p>
48
+
{/* Updates shown with each click */}
49
+
<p>Last updated: {Date.now()}</p>
50
+
</Show>
51
+
</div>
52
+
);
53
+
}
34
54
```
35
55
36
-
Ifthe`keyed`propertyisnotused, theargumentofthechildfunction will be an accessor containing the item.
56
+
## Render function
57
+
58
+
The `<Show>` component can also accept a render function as its child.
59
+
In this case, the first argument of the render function is an _accessor_ to the `when` prop.
60
+
However, when the `keyed` prop is set to `true`, the argument is the `when` prop itself instead of an accessor.
61
+
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.
65
+
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.
0 commit comments