I need to transfer some props into my component.
type Props = {
icon: number,
onChangeText: Function,
onEndEditing: Function,
placeholder: string,
secureTextEntry?: boolean
};
export default function LRInput(
props: Props = { ...props, secureTextEntry: false } // I've tried to do it in this way, but it hasn't worked
) { /*function body*/ }
You can see that secureTextEntry is an optional parameter. So, I want to define some default value for this prop. How can I do this?
I wouldn't use destructuring at all, rather put the optional property on a new object:
export default function LRInput(props: Props) {
const defaultedProps: Props = { secureTextEntry: false, ...props };
/* function body */
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments