Skip to content

Commit

Permalink
Add spread example
Browse files Browse the repository at this point in the history
  • Loading branch information
kodeFant committed Nov 2, 2024
1 parent e7522e3 commit 5c14759
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Guide/hsx.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,15 @@ This approach is particularly useful for:
- Domain-specific XML markup languages like [Hyperview](https://hyperview.org/docs/example_navigation)
- Integration with third-party frameworks that extend HTML syntax

It's not usable for libraries with very unusual symbols in their attributes, like Alpine.js. Even `uncheckedHsx` will throw an error because it doesn't recognize html attributes starting with `@` or has `:` in the attribute name. In these cases, the spread syntax `{...attributeList}` is likely your best bet.
`customHsx` whitelisting and even `uncheckedHsx` does not entirely help for libraries with very unusual symbols in their attributes, like Alpine.js, because they don't recognize html attributes starting with `@` or has `:` in the attribute name. In these cases, the spread syntax `{...attributeList}` is likely your best bet.

```haskell
-- This will not work
[uncheckedHsx|<button @click="open = true">Expand</button>|]

-- Using spread syntax will work
[hsx|<button {...[("@click", "open = true" :: Text)]}>Expand</button>|]
```

## Common HSX Patterns

Expand Down
9 changes: 8 additions & 1 deletion ihp-hsx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,15 @@ This approach is particularly useful for:
- Domain-specific XML markup languages
- Integration with third-party frameworks that extend HTML syntax

It's not usable for libraries with very unusual symbols in their attributes, like Alpine.js. Even `uncheckedHsx` will throw an error because it doesn't recognize html attributes starting with `@` or has `:` in the attribute name. In these cases, the spread syntax `{...attributeList}` is likely your best bet.
`customHsx` whitelisting and even `uncheckedHsx` does not entirely help for libraries with very unusual symbols in their attributes, like Alpine.js, because they don't recognize html attributes starting with `@` or has `:` in the attribute name. In these cases, the spread syntax `{...attributeList}` is likely your best bet.

```haskell
-- This will not work
[uncheckedHsx|<button @click="open = true">Expand</button>|]

-- Using spread syntax will work
[hsx|<button {...[("@click", "open = true" :: Text)]}>Expand</button>|]
```

## Common HSX Patterns

Expand Down

0 comments on commit 5c14759

Please sign in to comment.