Set the default value for the key of the function object parameter

Eugene

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?

Bergi

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.

edited at
0

Comments

0 comments
Login to comment

Related

Function that receives a function and a "default parameters" key-value object and returns another function with default arguments set

Set a default parameter value for a JavaScript function

Sending default parameter as null and use default value set in function

Set object key value by function result

How to set value for specific default value of a parameter in a javascript function

Default value for function as parameter

Can swift closures be set to a default value when used as a parameter in a function?

How to set a default value for an optional positional parameter of type Function?

Set default value for parameter of List<string> type in function

Python: How to set the default value when the parameter type is function?

Set function default this value

TypeScript: Function parameter types to update an object by key and value

Key value assignment in the object passed as a parameter in a arrow function for map

Dart set default value for parameter

Set default value and type for parameter

get function parameter with default value

JavaScript function default parameter value

Is It Possible To Set Default Parameter Value On A Rest Parameter

Interface of object parameter with default value and default property

[Basic typescript]: set the key of a function returned object to the value of it's param

Default identity value of a key function

Is there a way to make a Powershell function ignore a default parameter's value if its parameter set is not in use?

PHP, set default function parameter to result of function

lodash pick: set default value if key not set

How to determine whether function parameter was automatically set to default value or was set explicitly in C++?

What is the default value of the "default" parameter in dict.pop(key[, default])?

"Argument of type 'string' is not assignable to parameter of type never" in the parameter of the function call to get a value from an object key

How to set default value in function

Set a parameter Value of Function Js

TOP Ranking

HotTag

Archive