Skip to content

Commit 2bda9b9

Browse files
committed
update
1 parent 6b391a0 commit 2bda9b9

6 files changed

Lines changed: 60 additions & 24 deletions

File tree

src/routes/reference/component-apis/children.mdx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ The accessor also exposes `toArray()`.
5656
### Basic usage
5757

5858
```tsx
59-
import { children } from "solid-js";
60-
6159
function Wrapper(props) {
6260
const resolved = children(() => props.children);
6361

@@ -68,13 +66,20 @@ function Wrapper(props) {
6866
</div>
6967
);
7068
}
69+
70+
function Example() {
71+
return (
72+
<Wrapper>
73+
<span>First</span>
74+
<span>Second</span>
75+
</Wrapper>
76+
);
77+
}
7178
```
7279

7380
### Flatten children into an array
7481

7582
```tsx
76-
import { children } from "solid-js";
77-
7883
function List(props) {
7984
const resolved = children(() => props.children);
8085

@@ -86,6 +91,15 @@ function List(props) {
8691
</ul>
8792
);
8893
}
94+
95+
function Example() {
96+
return (
97+
<List>
98+
<span>Alpha</span>
99+
<span>Beta</span>
100+
</List>
101+
);
102+
}
89103
```
90104

91105
## Related

src/routes/reference/components/create-dynamic.mdx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,21 @@ Returns the rendered component or element.
6262
## Example
6363

6464
```tsx
65-
import { createDynamic } from "solid-js/web";
65+
const views = {
66+
red: () => <p style={{ color: "red" }}>Red</p>,
67+
blue: () => <p style={{ color: "blue" }}>Blue</p>,
68+
};
69+
70+
const [selected, setSelected] = createSignal<keyof typeof views>("red");
71+
72+
return (
73+
<>
74+
<button onClick={() => setSelected("red")}>Red</button>
75+
<button onClick={() => setSelected("blue")}>Blue</button>
6676

67-
function Example(props) {
68-
return createDynamic(() => props.as, { type: "button", children: "Save" });
69-
}
77+
<Dynamic component={views[selected()]} />
78+
</>
79+
);
7080
```
7181

7282
## Related

src/routes/reference/components/dynamic.mdx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ Returns the rendered component or element.
6666
## Example
6767

6868
```tsx
69-
import { Dynamic } from "solid-js/web";
69+
const views = {
70+
red: () => <p style={{ color: "red" }}>Red</p>,
71+
blue: () => <p style={{ color: "blue" }}>Blue</p>,
72+
};
73+
74+
const [selected, setSelected] = createSignal<keyof typeof views>("red");
75+
76+
return (
77+
<>
78+
<button onClick={() => setSelected("red")}>Red</button>
79+
<button onClick={() => setSelected("blue")}>Blue</button>
7080

71-
function Example(props) {
72-
return <Dynamic component={props.as} type="button" children="Save" />;
73-
}
81+
<Dynamic component={views[selected()]} />
82+
</>
83+
);
7484
```
7585

7686
## Related

src/routes/reference/components/error-boundary.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ Returns the rendered children or fallback content.
6464
### Basic usage
6565

6666
```tsx
67-
import { ErrorBoundary } from "solid-js";
68-
6967
<ErrorBoundary
7068
fallback={(error, reset) => (
7169
<div>

src/routes/reference/components/for.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,22 @@ Child function. It receives the current item and an index accessor.
7373
### Basic usage
7474

7575
```tsx
76-
<For each={items()} fallback={<div>No items</div>}>
76+
const items = ["A", "B", "C"];
77+
78+
<For each={items} fallback={<div>No items</div>}>
7779
{(item) => <div>{item}</div>}
7880
</For>;
7981
```
8082

8183
### Access the index
8284

8385
```tsx
84-
<For each={items()}>
86+
const items = ["A", "B", "C"];
87+
88+
<For each={items}>
8589
{(item, index) => (
8690
<div>
87-
#{index()} {item}
91+
#{index} {item}
8892
</div>
8993
)}
9094
</For>;

src/routes/reference/components/index-component.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
title: <Index>
33
use_cases: >-
4-
primitive arrays, non-keyed lists, index-based rendering, static positions,
4+
non-keyed lists, index-based rendering, fixed positions, changing values,
55
simple lists
66
tags:
77
- lists
88
- iteration
99
- components
1010
- arrays
11-
- primitives
1211
- index
1312
version: "1.0"
1413
description: >-
@@ -48,7 +47,7 @@ Source list.
4847

4948
- **Type:** `JSX.Element`
5049

51-
Content rendered when `each` is empty or falsy.
50+
Content rendered when `each` is an empty array, `undefined`, `null`, or `false`.
5251

5352
### `children`
5453

@@ -66,26 +65,27 @@ Child function. It receives an accessor for the item at that index and the index
6665
- The `item` argument is an accessor.
6766
- The `index` argument is a number.
6867
- Updating a value at the same index updates the corresponding rendered item.
68+
- When the array is reordered, rendered positions stay tied to indexes, and `item()` updates to the current value at that index.
6969
- `<Index>` uses [`indexArray`](/reference/reactive-utilities/index-array) internally.
7070

7171
## Examples
7272

7373
### Basic usage
7474

7575
```tsx
76-
import { Index } from "solid-js";
76+
const items = ["A", "B", "C"];
7777

78-
<Index each={state.list} fallback={<div>No items</div>}>
78+
<Index each={items} fallback={<div>No items</div>}>
7979
{(item) => <div>{item()}</div>}
8080
</Index>;
8181
```
8282

8383
### Access the index
8484

8585
```tsx
86-
import { Index } from "solid-js";
86+
const items = ["A", "B", "C"];
8787

88-
<Index each={state.list}>
88+
<Index each={items}>
8989
{(item, index) => (
9090
<div>
9191
#{index} {item()}

0 commit comments

Comments
 (0)