You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-16Lines changed: 19 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,15 +72,15 @@ const Step1 = () => {
72
72
73
73
### Wizard
74
74
75
-
`Wizard` is used to wrap your steps. Each child component will be treated as an individual step. You can set a shared `footer` and `header` that always should be in your steps. Example: pass an action button component that contain a "previous" and "next" button.
75
+
`Wizard` is used to wrap your steps. Each child component will be treated as an individual step. You can pass a shared `footer` and `header`component that should always be in your steps.
76
76
77
-
Place the `Wizard` around it and that's it.
77
+
Example: pass a footer component that contains a "previous" and "next" button to the wizard.
78
78
79
79
#### Props
80
80
81
81
| name | type | description | required | default |
| nextStep | () => Promise<void> | Go to the next step |
140
138
| previousStep | () => void | Go to the previous step |
141
-
| handleStep | (handler: Handler) => void | Connect a callback that will be called when calling `nextStep`. `handler` can be either sync or async |
142
-
| isLoading | (props?: IntercomProps) => void |\* Will reflect the handler promise state: will be `true` if the handler promise is pending and |
143
-
|\*`false` when the handler is either fulfilled or rejected |
139
+
| handleStep | (handler: Handler) => void | Attach a callback that will be called when calling `nextStep`. `handler` can be either sync or async |
140
+
| isLoading | boolean |\* Will reflect the handler promise state: will be `true` if the handler promise is pending and `false` when the handler is either fulfilled or rejected |
144
141
| activeStep | number | The current active step of the wizard |
145
142
| isFirstStep | boolean | Indicate if the current step is the first step (aka no previous step) |
146
143
| isLastStep | boolean | Indicate if the current step is the last step (aka no next step) |
@@ -172,7 +169,7 @@ const Step1 = () => {
172
169
handleStep,
173
170
} =useWizard();
174
171
175
-
handleStep(() => {
172
+
handleStep(() => {
176
173
alert('Going to step 2');
177
174
});
178
175
@@ -193,14 +190,14 @@ const Step1 = () => {
193
190
};
194
191
```
195
192
196
-
It's recommended to put the shared components in the `header` or `footer` in the `Wizard` to avoid duplication.
193
+
It's recommended to pass the shared components to the `header` or `footer` in the `Wizard` to avoid duplication.
197
194
198
195
## Examples
199
196
Go to [examples](https://github.com/devrnt/react-use-wiard/tree/master/examples) to check see some examples
200
197
201
198
## Async
202
199
203
-
You can connect an async step handler to a step as well. Make sure to make to either pass an async function or return a promise (async) function:
200
+
You can attach an async step handler to a step as well. Make sure to make to either pass an async function or return a promise (async) function:
204
201
205
202
```ts
206
203
const Step1 = () => {
@@ -211,6 +208,8 @@ const Step1 = () => {
211
208
awaitfetch(...);
212
209
});
213
210
211
+
// OR
212
+
214
213
// Return promise
215
214
handleStep(() => {
216
215
returnfetch(...);
@@ -220,11 +219,15 @@ const Step1 = () => {
220
219
}
221
220
```
222
221
223
-
The `isLoading` of `useWizard` will indicate the loading state of the step when calling `nextStep`. If no errors are thrown the wizard will go to the next step, so no need to call this manually. If an error is thrown in the conencted function the wizard will just stay at the same step and will rethrow the error. (So you can try-catch in your connected function).
222
+
### Errors
223
+
If no errors are thrown then the wizard will go to the next step, so no need to call `nextStep` by yourself.
224
+
225
+
If an error is thrown in the conencted function the wizard will just stay at the same step and will rethrow the error. (So you can try-catch in your attached function).
224
226
225
-
If an async function is connected the `isLoading` of `useWizard` will indicate the loading state of the function.
227
+
### IsLoading
228
+
If an async function is attached to `handleStep` the `isLoading` property will indicate the loading state of the function. In general `isLoading` will reflect the handler promise state: will be `true` if the handler promise is pending and `false` when the handler is either fulfilled or rejected.
226
229
227
230
## Animation
228
-
Since `react-use-wizard` is focused to manage the logic of a wizard doesn't mean you can't add some animation by your own. Add any animation library that you like. I highly suggest (https://www.framer.com/motion/)[framer-motion].
231
+
Since `react-use-wizard` is focused to manage the logic of a wizard it doesn't mean you can't add some animation by your own. Add any animation library that you like. I highly suggest [framer-motion](https://www.framer.com/motion/) to add your animations.
229
232
230
-
Checkout this (https://github.com/devrnt/react-use-wizard/blob/docs/readme/example/components/animatedStep.tsx)[example] to see an animation to a step can be added.
233
+
Checkout this [example](https://github.com/devrnt/react-use-wizard/blob/docs/readme/example/components/animatedStep.tsx) to see how a step can be animated with framer motion.
0 commit comments