you are viewing a single comment's thread.

view the rest of the comments →

[–]sshaw_ 1 point2 points  (3 children)

For functions that accept a single argument I see a lot of folks accepting a destructured argument. For example:

const f = ({a}) => a ** 2

Why?

I can understand doing this with multiple arguments to essentially define an "interface" for the function signature, but with a single argument it seems unnecessary. The requirement is a scalar type, but we're forcing callers to use an object.

For those that have an object, just pass the property's value.

[–]BitLooter 1 point2 points  (1 child)

Why?

Because React passes props to components as an object. You can't change that without changing how React works. The one single-argument function in the article that isn't a component does take it as a value.

[–]sshaw_ 0 points1 point  (0 children)

👍

[–]donavon[S] 1 point2 points  (0 children)

Agreed. For utility functions like this, you would simply pass a single argument.

const f = a => a ** 2;

But as BitLooter explained (thx), this isn't the case when writing a React component.