ljharb / prop-types-tools

Custom React PropType validators
MIT License
671 stars 50 forks source link

Remove arity check from ref prop type #57

Closed ahuth closed 5 years ago

ahuth commented 5 years ago

In #54 we added a ref prop type, and in #55 added an arity check for callback refs. Unfortunately, that breaks a common pattern of having an empty function as a default value. For example:

function SomeButton({ buttonRef }) {
  return <button buttonRef={buttonRef} />;
}

SomeButton.defaultProps = {
  buttonRef() {}
};

We could leave the arity check and change default values to undefined, instead. However, that's an unknown amount of work, and I think we're better off removing the arity check and accepting functions with any number of arguments.

@ljharb , what do you think?

ljharb commented 5 years ago

Fair point; we could also accept both 0 and 1 but then are we really rejecting anything useful?

ahuth commented 5 years ago

Thanks!