Skip to content

(child)

JSX children selected by position or value

clojure
(child pos? val?)

Where:

  1. pos: position in the list (1-based) *
  2. val: child value at that position *

Matching:

  1. text children, e.g. <Link>text</Link>
  2. expression children, e.g. <Link>{expr}</Link>
  3. 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 } but not in { }:

typescript
<List>
  <Item />
  <Item />
</List>

Arguments

pos

• Number

Does NOT support: CompositionFree-form SelectionRefinementReplacement

val

(:kind) (:ref) (:text) (arr) (attr) (bool) (call) (child) (comp) (export) (fun) (id) (id+) (import) (jsx) (mem) (null) (num) (obj) (of) (prop) (regex) (regex+) (str) (str*) (str+) (tpl) (tpl*) (var) (:into) (:and) (:or) (:not) (:replace) (:capture)

Copyright © 2022-present Semantic Works, Inc.