Escribí la función React para renderizar la tabla. Así es como se ve la mesa.
Como parámetro toma JSON:
{ "id": 1, "firstName": "Richard", "lastName": "Morrison", "numberOfAccidents": 1 }, { "id": 3, "firstName": "Gregory", "lastName": "House", "numberOfAccidents": 5 }Parte de la función de tabla que representa filas:
<tbody {...getTableBodyProps()}> {rows.map((row) => { prepareRow(row) return ( <tr {...row.getRowProps()}> {row.cells.map(cell => { return <td {...cell.getCellProps()}>{cell.render('Cell')}</td> })} </tr> ) })} </tbody>Quiero agregar un enlace a '/paciente/$id' a cada fila. Traté de escribir algo como:
return <td to={'/patient/' + cell.getCellProps().data.id} {...cell.getCellProps()}>{cell.render('Cell')}</td>y
const handlerRowClick = (row) => { history.push(`/patient/${row.original.id}`); } ... return <td onClick={() => handlerRowClick(row)} {...cell.getCellProps()}>{cell.render('Cell')}</td>pero no funciona Me gustaría pedir consejos o enlaces que me puedan ayudar a resolver mi problema.
Debe usar NavLink en react-router-dom .
import { NavLink } from "react-router-dom"; <td {...cell.getCellProps()}> <NavLink to={`/patient/` + cell.getCellProps().data.id}> {cell.render("Cell")} </NavLink> </td>