Skip to content

Make invalid prop type warnings more specific if they are falsy #11289

Closed
@sebmarkbage

Description

@sebmarkbage

This is a common pattern:

<div onClick={condition && () => {}} className={condition && 'foo'} />

However if condition is false, 0 or "" then this correctly warns.

You should have used condition ? ... : undefined instead.

We could suggest that more specifically in the warning.

The longer term alternative is to use the proposed more concise ?? operator.

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