Skip to content

react/jsx-no-target-blank not working as expected on conditionals #3462

Closed

Description

Code

const openInNewTab = true; // could be true or false

export default function App() {
  return (
    <a
      href="https://google.com"
      target={openInNewTab ? "_blank" : "self"}
      rel={openInNewTab ? "noreferrer" : undefined}
    >
      Open Google
    </a>
  );
}

Currently what's happening

If I pass target='_blank' based on some condition as shown in the above snippet, and pass rel='noreferrer' on same condition. It is still showing me warning/error as per the config.

What should happen?

Ideally if the condition is same for both the props it should recognise it and should not give us warning/error.

Please let me know if I am missing something?

Reference:

Sample Codesandbox - https://codesandbox.io/s/mystifying-lake-l0420z?file=/src/App.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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