|
1 | 1 | import * as React from 'react'; |
2 | 2 |
|
| 3 | +import * as logger from './logger'; |
3 | 4 | import { Handler, WizardProps } from './types'; |
4 | 5 | import WizardContext from './wizardContext'; |
5 | 6 |
|
@@ -62,10 +63,33 @@ const Wizard: React.FC<WizardProps> = React.memo( |
62 | 63 | [doNextStep, previousStep, isLoading, handleStep, activeStep], |
63 | 64 | ); |
64 | 65 |
|
65 | | - const activeStepContent = React.useMemo( |
66 | | - () => React.Children.toArray(children)[activeStep], |
67 | | - [activeStep, children], |
68 | | - ); |
| 66 | + const activeStepContent = React.useMemo(() => { |
| 67 | + const reactChildren = React.Children.toArray(children); |
| 68 | + |
| 69 | + if (__DEV__) { |
| 70 | + // No steps passed |
| 71 | + if (reactChildren.length === 0) { |
| 72 | + logger.log( |
| 73 | + 'warn', |
| 74 | + 'Make sure to pass your steps as children in your <Wizard>', |
| 75 | + ); |
| 76 | + } |
| 77 | + // The passed start index is invalid |
| 78 | + if (activeStep > reactChildren.length) { |
| 79 | + logger.log('warn', 'An invalid startIndex is passed to <Wizard>'); |
| 80 | + } |
| 81 | + // Invalid header element |
| 82 | + if (header && !React.isValidElement(header)) { |
| 83 | + logger.log('error', 'Invalid header passed to <Wizard>'); |
| 84 | + } |
| 85 | + // Invalid footer element |
| 86 | + if (footer && !React.isValidElement(footer)) { |
| 87 | + logger.log('error', 'Invalid footer passed to <Wizard>'); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + return reactChildren[activeStep]; |
| 92 | + }, [activeStep, children, header, footer]); |
69 | 93 |
|
70 | 94 | return ( |
71 | 95 | <WizardContext.Provider value={wizardValue}> |
|
0 commit comments