Skip to content
Gx
GitHub

GX2005: attribute spread on a component

{...expr} puts attributes on an HTML element only.

Cause

{...expr} puts attributes on an HTML element only. A component does not take attributes that it does not declare.

Example

ui/card/Card.gx
package card

props {
  Title string
}

<article>{p.Title}</article>
ui/card/Page.gx
package card

props {
  Attrs gx.Attrs = nil
}

<Card title="News" {...p.Attrs} />

gx check reports:

gx check
ui/card/Page.gx:7:20: GX2005: attributes cannot spread onto <Card>; pass a gx.Attrs prop instead

Fix

  1. Give the component a prop of type gx.Attrs.
  2. Pass the attributes to that prop, for example attrs={p.Attrs}.