Skip to content

Using React Router's <Link /> to wrap a table row #2336

Answered by GuptaSiddhant
LydiaF asked this question in General
Discussion options

You must be logged in to vote

Unfortunately you can't do this. This is not react-table's issue.
This is an HTML issue which requires td to be direct children of tr. All other elements like div or Link should be inside td.

But as I can you want link the whole row. You can use the onClick prop on tr to achieve the same result. The catch is you have to use history api to manipulate your browser.

import { useHistory } from "react-router-dom";

const Table = () => {
  ...
  const history = useHistory();
  const handleRowClick = (row) => {
    history.push(`/use-cases/${row.original.id}`);
  }  

  return (
    ...
    <tr onClick={()=> handleRowClick(row)}}>
      ...
    </tr>
    ...
  );
}

Replies: 8 comments 11 replies

Comment options

You must be logged in to vote
1 reply
@LydiaF
Comment options

Comment options

You must be logged in to vote
7 replies
@gedankennebel
Comment options

@Siymiel
Comment options

@Ahmadhonnee
Comment options

@Ahmadhonnee
Comment options

@gjj
Comment options

Answer selected by LydiaF
Comment options

You must be logged in to vote
2 replies
@TheRealPiotrP
Comment options

@TomNewton1
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dlibis
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet