Writing UI components
const Auth = () => {
const [auth, dispatch] = useAuth()
return match(auth, {
UNAUTHENTICATED: () => <button onClick={
() => dispatch{ type: 'SIGN_IN' })
}>Sign In</button>,
AUTHENTICATING: () => <button disabled={true}>Signing In...</button>,
AUTHENTICATED: ({ user }) => <Dashboard user={user} />,
ERROR: ({ error }) => <h4>Oh no, ${error}</h4>
})
}Matching to styles
const SomeComponent = () => {
const [auth] = useAuth()
const style = match(auth, {
UNAUTHENTICATED: () => ({ opacity: 1 }),
AUTHENTICATING: () => ({ opacity: 0.5 }),
AUTHENTICATED: () => ({ opacity: 0 }),
ERROR: () => ({ opacity: 1 })
})
}Matching to variants
What is feature and what is UI?
Explicit states for complex interactions
Last updated
Was this helpful?