-
Notifications
You must be signed in to change notification settings - Fork 350
Reference section updates updates #1460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LadyBluenotes
wants to merge
94
commits into
main
Choose a base branch
from
ref-updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
94 commits
Select commit
Hold shift + click to select a range
30ba3de
docs: enhance documentation for batch, onCleanup, onMount, and untrack
LadyBluenotes 80c4b9d
docs: update descriptions for batch, catchError, getOwner, onCleanup,…
LadyBluenotes da1b83e
docs: update documentation for createReaction, startTransition, and u…
LadyBluenotes d448223
docs: update documentation for from, indexArray, mapArray, and observ…
LadyBluenotes c4de20b
docs: refine documentation for children, createContext, useContext, a…
LadyBluenotes 67a8923
docs: update documentation for createContext, createDeferred, createR…
LadyBluenotes 2057f6a
docs: update documentation for <Dynamic>, mergeProps, <Portal>, and s…
LadyBluenotes 0374d22
docs: update documentation for <Dynamic>, mergeProps, <Portal>, and s…
LadyBluenotes b1c0bd4
docs: update documentation for <Dynamic>, mergeProps, <Portal>, and s…
LadyBluenotes e2091bc
migrate rendering reference pages and split isDev
LadyBluenotes e3b30c6
migrate server rendering reference pages
LadyBluenotes ed22b63
migrate server rendering reference pages
LadyBluenotes 6d1abb5
migrate store creation and mutable store refs
LadyBluenotes b389663
migrate store creation and mutable store refs
LadyBluenotes 313cd7a
migrate jsx attribute refs and attribute directives
LadyBluenotes 20117b9
add warning to suspense list
LadyBluenotes 921e3b1
jsx styling and content attribute refs
LadyBluenotes 759a60b
jsx event and directive reference pages
LadyBluenotes d992ace
update children
LadyBluenotes 599b55c
update
LadyBluenotes 7c4ba3c
update
LadyBluenotes 78ba488
update
LadyBluenotes 6b391a0
update
LadyBluenotes 2bda9b9
update
LadyBluenotes d00622e
update
LadyBluenotes b25c82b
update
LadyBluenotes 878aa46
update
LadyBluenotes 8d5a5ae
update
LadyBluenotes b310a12
update
LadyBluenotes cc37151
update
LadyBluenotes 4d7eb35
update
LadyBluenotes b94ffde
update
LadyBluenotes a252fae
update
LadyBluenotes ff0dcdb
update
LadyBluenotes d0217b0
update
LadyBluenotes 0ef73e8
update
LadyBluenotes bf31ca0
update
LadyBluenotes 9515e10
update
LadyBluenotes 05cfd33
update
LadyBluenotes b0139d4
update
LadyBluenotes 91b3aba
update
LadyBluenotes 4c2276e
update
LadyBluenotes 783dcd9
update
LadyBluenotes 890f5bb
update
LadyBluenotes 4045d18
update
LadyBluenotes 63e122d
update
LadyBluenotes 13744eb
update
LadyBluenotes caa8736
update
LadyBluenotes 5dfe7e0
Merge branch 'main' into ref-updates
kodiakhq[bot] ffede2d
update
LadyBluenotes a975566
ci: apply automated fixes
autofix-ci[bot] 1c42276
Merge remote-tracking branch 'origin/ref-updates' into ref-updates
LadyBluenotes cd3aa56
update
LadyBluenotes 5d14672
ci: apply automated fixes
autofix-ci[bot] 8253297
update
LadyBluenotes c434bbc
Merge remote-tracking branch 'origin/ref-updates' into ref-updates
LadyBluenotes 5c821e0
update
LadyBluenotes f9b8140
ci: apply automated fixes
autofix-ci[bot] 31e5840
update
LadyBluenotes 4909ac8
Merge remote-tracking branch 'origin/ref-updates' into ref-updates
LadyBluenotes ff496a5
update
LadyBluenotes ad3cd90
update
LadyBluenotes 799f08e
update
LadyBluenotes acad606
update
LadyBluenotes 9ef7a8d
update
LadyBluenotes 2b3e4f9
update
LadyBluenotes 30e49f0
update
LadyBluenotes de7692a
update
LadyBluenotes 41afcb6
update
LadyBluenotes cb94434
update
LadyBluenotes 12320a7
update
LadyBluenotes c6373b3
update
LadyBluenotes 943bf96
update
LadyBluenotes 2b8579a
update
LadyBluenotes a40025d
update
LadyBluenotes 8110eda
update
LadyBluenotes 41550a3
update
LadyBluenotes 1ba58f3
update
LadyBluenotes 1f10d22
update
LadyBluenotes 41c389d
update
LadyBluenotes e7d189e
update
LadyBluenotes b2b8a1b
update
LadyBluenotes cd19e35
update
LadyBluenotes b6c3f87
update
LadyBluenotes ed5a2c7
improve accuracy of docs
LadyBluenotes 431f2f2
ci: apply automated fixes
autofix-ci[bot] 666143c
update docs for accuracy
LadyBluenotes 9ee6e50
Merge remote-tracking branch 'origin/ref-updates' into ref-updates
LadyBluenotes e0f4812
update docs for accuracy
LadyBluenotes 1e410e6
update docs for accuracy
LadyBluenotes b7a9c9d
update docs for accuracy
LadyBluenotes 44fe189
update docs for accuracy
LadyBluenotes 27a34a2
update docs for accuracy
LadyBluenotes 6decc54
Merge branch 'main' into ref-updates
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,10 @@ tags: | |
| - utilities | ||
| version: "1.0" | ||
| description: >- | ||
| Resolve and normalize a component's `children` prop into a stable accessor. | ||
| Useful when you need to read or transform children imperatively inside a | ||
| component. | ||
| Resolve a component's `children` prop into a stable accessor. | ||
| --- | ||
|
|
||
| `children` normalizes a component's `children` prop into a stable accessor that returns resolved JSX elements. | ||
| It accepts functions, arrays, fragments, and nested structures. | ||
| `children` resolves a component's `children` prop and returns a stable accessor for the resolved result. | ||
|
|
||
| ## Import | ||
|
|
||
|
|
@@ -27,10 +24,11 @@ import { children } from "solid-js"; | |
| ## Type | ||
|
|
||
| ```ts | ||
| function children(fn: Accessor<JSX.Element>): ChildrenReturn; | ||
| type ResolvedJSXElement = Exclude<JSX.Element, JSX.ArrayElement>; | ||
| type ResolvedChildren = ResolvedJSXElement | ResolvedJSXElement[]; | ||
|
|
||
| type ChildrenReturn = Accessor<ResolvedChildren> & { | ||
| toArray: () => ResolvedChildren[]; | ||
| function children(fn: Accessor<JSX.Element>): Accessor<ResolvedChildren> & { | ||
| toArray: () => ResolvedJSXElement[]; | ||
| }; | ||
| ``` | ||
|
|
||
|
|
@@ -41,24 +39,20 @@ type ChildrenReturn = Accessor<ResolvedChildren> & { | |
| - **Type:** `() => JSX.Element` | ||
| - **Required:** Yes | ||
|
|
||
| An accessor that returns the `children` value (typically `props.children`). | ||
| Accessor that returns the component's `children` value. | ||
|
|
||
| ## Return value | ||
|
|
||
| - **Type:** `ChildrenReturn` | ||
| - **Type:** `Accessor<ResolvedChildren> & { toArray: () => ResolvedJSXElement[] }` | ||
|
|
||
| The function returns a callable accessor. | ||
| Calling it yields the resolved children, either a single element or an array. | ||
| Returns an accessor for the resolved children. | ||
| The accessor also exposes `toArray()`. | ||
|
|
||
| ## Helpers | ||
| ## Behavior | ||
|
|
||
| ### `toArray()` | ||
|
|
||
| - **Type:** `() => ResolvedChildren[]` | ||
|
|
||
| - **Description:** Returns a flattened array of resolved child elements. | ||
|
|
||
| This method is exposed on the returned accessor and is useful for iteration or index-based logic. | ||
| - The returned accessor memoizes the resolved children, so repeated reads use the resolved result instead of recreating the child structure. | ||
| - `children` resolves nested arrays, fragments, and zero-argument child accessors from `props.children`. | ||
| - `toArray()` returns the resolved children as an array. It returns `[]` when the resolved value is `null` or `undefined`. | ||
|
|
||
| ## Examples | ||
|
|
||
|
|
@@ -68,53 +62,49 @@ This method is exposed on the returned accessor and is useful for iteration or i | |
| function Wrapper(props) { | ||
| const resolved = children(() => props.children); | ||
|
|
||
| return <div>{resolved()}</div>; | ||
| return ( | ||
| <div> | ||
| <header>{resolved()}</header> | ||
| <div>{resolved()}</div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // Usage | ||
| <Wrapper> | ||
| <span>one</span> | ||
| <span>two</span> | ||
| </Wrapper>; | ||
| function Example() { | ||
| return ( | ||
| <Wrapper> | ||
| <span>First</span> | ||
| <span>Second</span> | ||
| </Wrapper> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### `.toArray()` example | ||
| ### Flatten children into an array | ||
|
|
||
| ```tsx | ||
| function List(props) { | ||
| const resolved = children(() => props.children); | ||
| const items = resolved.toArray(); | ||
|
|
||
| return ( | ||
| <ul> | ||
| {items.map((child) => ( | ||
| {resolved.toArray().map((child) => ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call! |
||
| <li>{child}</li> | ||
| ))} | ||
| </ul> | ||
| ); | ||
| } | ||
|
|
||
| // Usage | ||
| <List> | ||
| <span>one</span> | ||
| <span>two</span> | ||
| </List>; | ||
| function Example() { | ||
| return ( | ||
| <List> | ||
| <span>Alpha</span> | ||
| <span>Beta</span> | ||
| </List> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > `children` resolves the current value of `props.children`. | ||
| > If `props.children` is reactive, the resolved accessor reflects updates. | ||
|
|
||
| ### Working with function-as-children | ||
| ## Related | ||
|
|
||
| If `children` is a function, the helper evaluates it and returns its rendered result. | ||
|
|
||
| ```tsx | ||
| function Slot(props) { | ||
| const resolved = children(() => props.children); | ||
| return <div>{resolved()}</div>; | ||
| } | ||
|
|
||
| // Usage | ||
| <Slot>{() => <span>dynamic</span>}</Slot>; | ||
| ``` | ||
| - [Props](/concepts/components/props) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think the previous example was better as to not encourage using the resolved children more than once.
If it were text children, then that example would have been ok,
https://playground.solidjs.com/anonymous/3b9366fa-717d-4c0c-8834-d2a69a455361
but if the children happen to be warpped in a div, then that div will only exist in 1 place at a time
https://playground.solidjs.com/anonymous/ca5d31b9-69e6-4609-b8cc-6545834644c0
the children helper wraps the function in a memo, that caches the value, so each time its called, it returns the same thing (as in, it wont create two divs)