Steps
Render your steps with <StepRouter> and <Step> from @picked/react or
@picked/svelte. Reach the active step through useStep() or getStep().
Reach the step context
Inside a Step component, or inside any component that a Step renders, call
getStep() or useStep() to reach the reactive context of the step:
import { useStep, useStoreGlobal } from '@picked/react/hooks'
function ContactForm() {
const { step, fields } = useStep()
const currentStep = useStoreGlobal(step)
const currentFields = useStoreGlobal(fields)
return (
<>
<h1>{currentStep.label}</h1>
{currentFields.map((field) => (
<div key={field.id}>
<label>{field.label}</label>
<input
name={field.id}
value={field.value ?? ''}
onChange={field.onChange}
onBlur={field.onBlur}
/>
{field.error && field.touched && <p className="error">{field.error.userMessage}</p>}
</div>
))}
</>
)
}<script lang="ts">
import { getStep } from '@picked/svelte/hooks'
const { step, fields } = getStep()
</script>
<h1>{$step.label}</h1>
{#each $fields as field}
<label>{field.label}</label>
<input
name={field.id}
value={field.value ?? ''}
onchange={field.onChange}
onblur={field.onBlur}
/>
{#if field.error && field.touched}
<p class="error">{field.error.userMessage}</p>
{/if}
{/each}getStep() in Svelte, and useStep() in React, return a StepContext with these
properties:
| Property | Type | Description |
|---|---|---|
step | Store<ExperienceStep> | A reactive store that holds the id and the label of the step |
fields | Store<FormField[]> | A reactive store of the fields, with their current values, errors, and handlers |
isActive | Store<boolean> (Svelte) / boolean (React) | Whether the router holds this step as the active one |
form | Object | The handlers for a form submission. See Forms. |
Related
- How to render a step form
- How to run code on a form submission
- About how Picked works — why a flow is a graph.
