Props checked per element
Each field is checked against the element's attributes and events. Every attribute takes a value or an accessor.
link :: Accessor Boolean -> Accessor String -> JSX
link isActive label =
-- no: a div has no href
-- H.div { href: "/docs" } []
-- no: disabled is a Boolean
-- H.button { disabled: "yes" } []
H.a { href: "/docs", class: { active: isActive } } label
Setup can't write
Components run in Setup, which creates signals, memos and effects. Writes happen in handlers, in Effect.
counter :: Component.Component {}
counter = Component.component \_ -> do
count /\ setCount <- createSignal 0
doubled <- createMemo ((_ * 2) <$> count)
-- no: setup can't write signals
-- set setCount 1
pure $ H.button
{ onClick: \_ -> modify_ setCount (_ + 1) }
(show <$> doubled)
Async can't be read early
createAsync gives an Async with no get: render it, derive from it or await it, and loading shows a fallback.
user :: Component.Component { id :: Accessor Int }
user = Component.component \{ id } -> do
found /\ _ <- createAsync (fetchUser <$> id)
-- no: it may not have loaded
-- name <- get found
pure $ Control.loading (H.p {} "Loading…")
(H.h1 {} (_.name <$> found))
Routes typed by their path
A route's params come from its pattern, :id<int> arrives as an Int, and href builds links from the same pattern.
routes :: Array Router.Route
routes =
-- no: id is an Int
-- href @"/users/:id<int>" { id: "7" }
[ Router.route @"/users/:id<int>" \{ params } ->
pure (H.h1 {} (show <<< _.id <$> params))
, Router.route @"/" \_ -> pure $
H.a { href: href @"/users/:id<int>" { id: 7 } } "7"
]
ARIA from the spec
aria-* attributes follow WAI-ARIA 1.2: booleans, numbers, and a type for each set of keywords.
menu :: Accessor Boolean -> JSX
menu isOpen =
-- no: it's a Boolean
-- "aria-expanded": "true"
-- no: it's a HasPopup, with no "menus"
-- "aria-haspopup": "menus"
H.div { role: "toolbar" }
[ H.button { "aria-expanded": isOpen } "Details"
, H.button { "aria-haspopup": Aria.Menu } "Menu"
, H.p { "aria-live": Aria.Polite } "Saved"
]
Server code stays on the server
In start mode a server module's functions never reach the browser, and what crosses the wire must be Serializable.
module App.Api
( module Solid.Start.UseServer
, greet
) where
import Prelude
import Solid.Start.ServerFunction as Server
import Solid.Start.UseServer (useServer)
greet :: Server.ServerFunction String String
greet = Server.serverFunction \name ->
pure ("Hello, " <> name)