(child) - JavaScript
JSX children selected by position or value
clojure
(child pos? val?)Where:
Matching:
- text children, e.g.
<Link>text</Link> - expression children, e.g.
<Link>{expr}</Link> - element children, e.g.
<Link><Icon /></Link>
Behavior
- With only a position,
(child N)matches elements that have a child at that position. - Without position or value,
(child)only matches elements that have at least one child.
Examples
Find components that render untranslated text directly.
clojure
(jsx _ _ (child _ (str /welcome|hello/i)))Selects in lines { 1, 3 } but not in { 2 }:
typescript
<Header>Welcome</Header>
<Header>{t("welcome")}</Header>
<Footer>Hello there</Footer>Identify buttons whose first child is an icon component.
clojure
(jsx Button _ (child 1 (jsx Icon)))Selects in lines { 1 } but not in { 2, 3 }:
typescript
<Button><Icon />Save</Button>
<Button>Save<Icon /></Button>
<Link><Icon />Save</Link>Extract all direct children of a list for inspection.
clojure
(jsx List _ (child _ (:into)))Selects in lines { 2, 2 }:
typescript
<List>
<Item />
<Item />
</List>Arguments
pos
- Number
Does NOT support: Composition — Free-form Selection — Refinement — Replacement