JavaScript中函数传递等价性及无显式参数函数的参数接收疑问
(values) => handleClick(values)这类函数的参数接收问题? Great question! Let's unpack why this specific pattern doesn't get much spotlight:
It's a redundant "pass-through" wrapper
When you write(values) => handleClick(values), you're essentially creating an arrow function that does nothing but take whatever arguments it receives and pass them directly tohandleClick—no modification, no extra logic. This behaves exactly the same as passinghandleClickdirectly.For example:
// These two are functionally identical onClick={handleClick} onClick={(event) => handleClick(event)}React will pass the click event object to both versions, and
handleClickgets the exact same argument. Since this is a straightforward 1:1 parameter forward, it's considered self-explanatory—most developers assume the arguments will flow through correctly without needing to discuss it.Only modified parameter flows get attention
The conversation around arrow function wrappers usually starts when you need to alter the arguments or add extra data. For instance:// Now we're modifying/adding parameters—this is when people ask questions onClick={(event) => handleClick(event, "extraData")} setState={(prevState) => prevState + 1}These cases require intentional parameter handling, so they're the ones that get discussed. Your original example, though, doesn't change anything about the argument passing, so it flies under the radar.
Simplicity and best practices favor direct function passing
WritingonClick={handleClick}is cleaner than wrapping it in an unnecessary arrow function. It also avoids creating a new function on every render (a minor performance consideration, but still a common best practice). Since most developers opt for the simpler, more efficient version, the redundant wrapper pattern isn't something people encounter or question often.
In short: this pass-through wrapper is so straightforward and equivalent to direct function passing that it doesn't need special attention—only when you deviate from this 1:1 argument flow does the parameter handling become a topic of discussion.
内容的提问来源于stack exchange,提问作者Karita

