Skip to content

Commit 911398c

Browse files
docs: modernize Wizard Form example for little-state-machine v5 + React Router v6 (#1204)
1 parent 19f761a commit 911398c

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/content/advanced-usage.mdx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ It's pretty common to collect user information through different pages and secti
8989
**Step 1:** Set up your routes and store.
9090

9191
```javascript copy sandbox="https://codesandbox.io/s/react-hook-form-wizard-form-9pg6j"
92-
import { BrowserRouter as Router, Route } from "react-router-dom"
93-
import { StateMachineProvider, createStore } from "little-state-machine"
92+
import { BrowserRouter, Routes, Route } from "react-router-dom"
93+
import { createStore } from "little-state-machine"
9494
import Step1 from "./Step1"
9595
import Step2 from "./Step2"
9696
import Result from "./Result"
@@ -104,13 +104,13 @@ createStore({
104104

105105
export default function App() {
106106
return (
107-
<StateMachineProvider>
108-
<Router>
109-
<Route exact path="/" component={Step1} />
110-
<Route path="/step2" component={Step2} />
111-
<Route path="/result" component={Result} />
112-
</Router>
113-
</StateMachineProvider>
107+
<BrowserRouter>
108+
<Routes>
109+
<Route path="/" element={<Step1 />} />
110+
<Route path="/step2" element={<Step2 />} />
111+
<Route path="/result" element={<Result />} />
112+
</Routes>
113+
</BrowserRouter>
114114
)
115115
}
116116
```
@@ -119,16 +119,17 @@ export default function App() {
119119

120120
```javascript copy sandbox="https://codesandbox.io/s/react-hook-form-wizard-form-9pg6j"
121121
import { useForm } from "react-hook-form"
122-
import { withRouter } from "react-router-dom"
122+
import { useNavigate } from "react-router-dom"
123123
import { useStateMachine } from "little-state-machine"
124124
import updateAction from "./updateAction"
125125

126-
const Step1 = (props) => {
126+
export default function Step1() {
127127
const { register, handleSubmit } = useForm()
128-
const { actions } = useStateMachine({ updateAction })
128+
const { actions } = useStateMachine({ actions: { updateAction } })
129+
const navigate = useNavigate()
129130
const onSubmit = (data) => {
130131
actions.updateAction(data)
131-
props.history.push("./step2")
132+
navigate("/step2")
132133
}
133134

134135
return (
@@ -139,18 +140,15 @@ const Step1 = (props) => {
139140
</form>
140141
)
141142
}
142-
143-
export default withRouter(Step1)
144143
```
145144

146145
**Step 3:** Make your final submission with all the data in the store or display the resulting data.
147146

148147
```javascript copy sandbox="https://codesandbox.io/s/react-hook-form-wizard-form-9pg6j"
149148
import { useStateMachine } from "little-state-machine"
150-
import updateAction from "./updateAction"
151149

152-
const Result = (props) => {
153-
const { state } = useStateMachine(updateAction)
150+
export default function Result() {
151+
const { state } = useStateMachine()
154152

155153
return <pre>{JSON.stringify(state, null, 2)}</pre>
156154
}

0 commit comments

Comments
 (0)