Passing react-router <Link> component to the table cell
See original GitHub issueHello,
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:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
also, wouldn’t this work:
<TableHeaderColumn dataField='id' dataFormat={ this.colFormatter }>my header</TableHeaderColumn>
…and then:
That appears to work for me.
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> ) } }`