There are any ways of suppressing single validateDOMNesting warning in React?

Viewed 2355

In my case I have something like this:


<div className="projects">
  {getProjectList().map(p => (
    <Link key={p.id} 
          className='project' 
          to={`/project/${p.id}`} 
          style={{border: '2px solid red'}}
    >
        #{p.id} - {p.name}
        <div className="helpers">
          <Button
            icon="trash"
            size="mini"
            color="red"
            onClick={e => {
              e.preventDefault();
              e.stopPropagation();
              setDeleting(p);
            }}
          />
          <Button
            size="mini"
            color="red"
            as={Link}
            to={`/edit/${p.id}`}
          >Edit</Button>
        </div>
    </Link>
  ))}
</div>

which visually is represented like this:

enter image description here

And I would prefer to keep it like this because it works as it is intended.

Additional explanation why I want it this way: I want to provide to user ability to click on both links with right mouse button and choose "Open Link in New Tab". To navigate to details of the projects and also navigate to edit form to change properties of the project (These are two different pages).

But in this case I have two times tag embedded in each other and React generate:

Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>.

any ways to suppress it?

1 Answers

Just add /* eslint-disable */ in the file you want the warnings to be suppressed as explained in the official github repository how to hide unwanted warning.

Remember that's not best practice.

Related