Skip to content

Warn for PropTypes that don't exist but do exist with a different case #6153

@sebmarkbage

Description

@sebmarkbage
const Foo = ({ onAction }) => <div onClick={onAction} />;
Foo.propTypes = {
  onAction: PropTypes.function
};

const Bar = () => <Foo onaction={() => console.log('action')} />; // This should warn

We currently don't warn for properties that don't exist in the propTypes set. I.e. we don't catch typos. This is mostly a legacy artifact and there are many components out there that don't define their full set of props. E.g. when ... spread is used. Few components also define the children prop even though they use it. Warning for all of these might be too much work initially.

However, we can start small. We can find missing properties that have corresponding properties with a different case and suggest that the developer use that instead. This is essentially always a bug.

While it is technically possible to have the same property name with two or more different case, it is considered bad practice to allow both. It causes overhead to test for both in the diffing/rendering. It causes style-guide issues where people have to pick which style to use. It also makes it worth for tooling where search/replace can easily miss less commonly used variants. That's why React only allows a single case, and ideally so should custom components.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions