user11092881
user11092881

Reputation:

How do you provide an extra parameter to a function call if the argument is implicitly provided?

export const SelectedChoice: (choiceProps) => { ... }

<ChoicePicker {...props}

     onRenderItem={SelectedChoice}

/>

I have this, the argument choiceProps is implicitly provided, but now I want to add a function to the second argument so I can call it inside of SelectedChoice, how do I do this? The issue is that I don't know what is being passed to SelectedChoice so I can't call it explicitly without breaking the function. If I knew what was being passed as choiceProps, I wouldn't have this issue. I feel like it's being called as a callback function and the argument is explicitly provided inside onRenderItem, but I might be mistaken.

Upvotes: 2

Views: 57

Answers (1)

Christian
Christian

Reputation: 1260

You might be able to check the arguments object that implicitly exists in the function body of SelectedChoice as in:

export const SelectedChoice: (choiceProps) => {
   if(arguments.length === 1) {
      // do something if no function was passed
   }
   else if(arguments.length === 2 && typeof arguments[1] === "function") {
      // call the passed function
      arguments[1]();
   }
}

Upvotes: 4

Related Questions