Skip to content

(jsx) - JavaScript

JSX elements and fragments, matched by name, attributes, and children

clojure
(jsx name? attrs? children?)

Where:

  1. name: element name (the Button in <Button />, or <> for fragments) *
  2. attrs: attributes on the element *
  3. children: child nodes within the element *

Matching:

  1. elements, e.g. <div>...</div>
  2. self-closing elements, e.g. <Button />
  3. member and namespaced elements, e.g. <A.B />
  4. fragments, e.g. <>...</>

Behavior

  • Fragments only match when the name selector is <>.
  • Self-closing elements cannot match when a children selector is provided.

Examples

Find components rendered as fragments so they can be wrapped for styling.

clojure
(jsx <>)

Selects in lines { 1 } but not in { 2 }:

typescript
const A = () => <>Hello</>
const B = () => <div>Hello</div>

Identify buttons that still pass inline handlers for refactoring.

clojure
(jsx Button (attr onClick))

Selects in lines { 1 } but not in { 2, 3 }:

typescript
<Button onClick={track}>Save</Button>
<Button disabled>Save</Button>
<Link onClick={track}>Save</Link>

Find dialog components that render translated children.

clojure
(jsx Dialog _ (child _ (call t)))

Selects in lines { 1 } but not in { 2, 3 }:

typescript
<Dialog>{t("welcome")}</Dialog>
<Dialog>{"Welcome"}</Dialog>
<Modal>{t("welcome")}</Modal>

Arguments

name

attrs

children

Copyright © 2022-present Semantic Works, Inc.