如果您想让
RenderFooter
组件更加灵活并且在调用它时不需要任何参数,您可以为 props
参数提供默认值。您可以使用函数定义中的默认参数来执行此操作。以下是修改组件的方法:
const RenderFooter = (props: Props = {}): React.ReactElement => {
const { navigation } = props;
return (
<StickyFooter
accessibilityLabel="Introduction-Footer"
primaryButtonText={I18n.t('Introduction-Primary-Button-Text')}
secondaryButtonText={I18n.t('Introduction-Secondary-Button-Text')}
onPressPrimaryButton={() => navigate(navigation, 'LoginPage')}
onPressSecondaryButton={() => navigate(navigation, 'RegisterPage')}
/>
);
};
在此代码中,我为
{}
参数提供了空对象 props
的默认值。这意味着如果您不带任何参数调用 RenderFooter()
,它将使用一个空对象作为 props
。如果您使用参数调用它,它将使用提供的 props
。这允许您使用带参数和不带参数的组件。