MCPcopy Create free account
hub / github.com/WebDevSimplified/react-multistep-form / App

Function App

src/App.tsx:31–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29}
30
31function App() {
32 const [data, setData] = useState(INITIAL_DATA)
33 function updateFields(fields: Partial<FormData>) {
34 setData(prev => {
35 return { ...prev, ...fields }
36 })
37 }
38 const { steps, currentStepIndex, step, isFirstStep, isLastStep, back, next } =
39 useMultistepForm([
40 <UserForm {...data} updateFields={updateFields} />,
41 <AddressForm {...data} updateFields={updateFields} />,
42 <AccountForm {...data} updateFields={updateFields} />,
43 ])
44
45 function onSubmit(e: FormEvent) {
46 e.preventDefault()
47 if (!isLastStep) return next()
48 alert("Successful Account Creation")
49 }
50
51 return (
52 <div
53 style={{
54 position: "relative",
55 background: "white",
56 border: "1px solid black",
57 padding: "2rem",
58 margin: "1rem",
59 borderRadius: ".5rem",
60 fontFamily: "Arial",
61 maxWidth: "max-content",
62 }}
63 >
64 <form onSubmit={onSubmit}>
65 <div style={{ position: "absolute", top: ".5rem", right: ".5rem" }}>
66 {currentStepIndex + 1} / {steps.length}
67 </div>
68 {step}
69 <div
70 style={{
71 marginTop: "1rem",
72 display: "flex",
73 gap: ".5rem",
74 justifyContent: "flex-end",
75 }}
76 >
77 {!isFirstStep && (
78 <button type="button" onClick={back}>
79 Back
80 </button>
81 )}
82 <button type="submit">{isLastStep ? "Finish" : "Next"}</button>
83 </div>
84 </form>
85 </div>
86 )
87}
88

Callers

nothing calls this directly

Calls 1

useMultistepFormFunction · 0.90

Tested by

no test coverage detected