question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing react-router <Link> component to the table cell

See original GitHub issue

Hello,

got a problem trying to create a hyperlink inside a table cell using react-router <Link> component.

I wrote the following function:

function tenantLinkFormat(cell, row) {
    const link = <Link to="/users">cell</Link>;
    console.log(cell);
    console.log(link);
    return link;
}

And got this error message in console:

warning.js:36 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of TableBody.

The console output with the objects looks as follows: http://i.imgur.com/RyFGBCD.png

So it seems to me that everything is correct, but it isn’t apparently. Please point me to what should be fixed here.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

29reactions
bmueller-sykescommented, Dec 2, 2016

also, wouldn’t this work:

<TableHeaderColumn dataField='id' dataFormat={ this.colFormatter }>my header</TableHeaderColumn>

…and then:

  colFormatter = (cell, row) => {
    return (
      <Link to='/some/route'>
        {cell}
      </Link>
    )
  }

That appears to work for me.

3reactions
FreeClimbcommented, Apr 17, 2017

To navigate using a React Router, you can disable default behavior and turn on the onClick

`import React, { Component } from ‘react’ import { Route } from ‘react-router-dom’ import { BootstrapTable, TableHeaderColumn } from ‘react-bootstrap-table’ … class LinkTable extends Component {

hrefIdFormatter = (cell, row) => { const href = product/${row.id}; return ( <Route render={({ history }) => ( <a href={href} style={{ cursor: ‘pointer’ }} onClick={(e) => { // stop default behavior a href e.preventDefault(); // set state selected product id this.set({ …this.state, selected: row.id }); // go to the detail product page history.push(/product/${row.id}) }}> {row.id} )} />) } render() { return ( <BootstrapTable data={this.props.products}> <TableHeaderColumn dataSort={true} dataField=“id” width=“5%” thStyle={{ fontWeight: 500 }} tdStyle={{ fontSize: ‘0.8rem’ }} dataFormat={this.hrefIdFormatter} isKey>ID</TableHeaderColumn> … </BootstrapTable> ) } }`

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-router: Using <Link> as clickable data table row
Here's an example of a Td component that accepts to prop: import React from 'react'; import { Link } from 'react-router-dom'; export default ......
Read more >
React Router 6: Passing Data (States) through Links
This article shows you a concise and elegant approach to passing data through the Link component of React Router 6.
Read more >
How to Pass Props Through React Router's Link Component
To do this with React Router, we can pass data from the Link component through to the new Route that is being rendered....
Read more >
Making entire table row clickable using React Router Link ...
[Solved]-Making entire table row clickable using React Router Link-Reactjs ... can I pass props from one component to another using Link and router...
Read more >
Hooks FAQ - React
Do Hooks replace render props and higher-order components? What do Hooks mean for popular APIs like Redux connect() and React Router?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found