| 1 |
import { useEffect } from 'react'; |
| 2 |
import { useWizardContext } from '../WizardContext'; |
| 3 |
import { WizardFooterProps } from '../WizardFooter'; |
| 4 |
|
| 5 |
/** |
| 6 |
* Set a unique footer for the wizard. stepId is only required if inactive steps are hidden instead of unmounted. |
| 7 |
* @param footer |
| 8 |
* @param stepId |
| 9 |
*/ |
| 10 |
export const useWizardFooter = ( |
| 11 |
footer: React.ReactElement<any> | Partial<WizardFooterProps>, |
| 12 |
stepId?: string | number |
| 13 |
) => { |
| 14 |
const { activeStep, setFooter } = useWizardContext(); |
| 15 |
|
| 16 |
useEffect(() => { |
| 17 |
if (footer && (!stepId || activeStep?.id === stepId)) { |
| 18 |
setFooter(footer); |
| 19 |
|
| 20 |
// Reset the footer on unmount. |
| 21 |
return () => { |
| 22 |
setFooter(null); |
| 23 |
}; |
| 24 |
} |
| 25 |
}, [activeStep, footer, setFooter, stepId]); |
| 26 |
}; |