How to select and get all the values of rows and columns of Table in React js on Click and pass it to other Component...Help Me im stuck in this - reactjs

So I have Created Custom Table Component for my data to show and i want to get all the rows value with the Heading on Click of it and pass it to any component
This is COde of my table Component
import PlaceBett from "./PlaceBett";
const MatchBetTable = ({ data }) => {
const [showPlaceBet, setShowPlaceBet] = useState(false);
const [team1Back, setTeam1Back] = useState("");
const [team1Lay, setTeam1Lay] = useState("");
const [team2Lay, setTeam2Lay] = useState("");
const [team2Back, setTeam2Back] = useState("");
const [drawLay, SetDrawLay] = useState("");
const [drawBack, SetDrawBack] = useState("");
const handleClick = () => {
setShowPlaceBet((prev) => !prev);
};
// console.log(data.values[0].val1);
console.log(data);
return (
<>
{showPlaceBet && (
<PlaceBett
data={data}
team1Back={team1Back}
team1Lay={team1Lay}
team2Back={team2Back}
team2Lay={team2Lay}
drawBack={drawBack}
drawLay={drawLay}
/>
)}
<table className="table-auto mb-4 text-black w-full ">
<thead className="bg-gray-500 md:p-5 p-1 text-sm">
<tr>
<th className="md:p-5 p-1 text-sm">{data.name}</th>
<th className="md:p-5 p-1 text-sm" colSpan="5"></th>
<th className="md:p-5 p-1 text-sm">BET DELAY-3 SEC</th>
</tr>
</thead>
<thead>
<tr
className="bg-white md:p-5 p-1 text-sm border border-table_border"
onClick={handleClick}
>
<th className="md:p-5 p-1 text-sm">MAX 50000</th>
<th className="md:p-5 p-1 text-sm" colSpan="2"></th>
<th className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
BACK <p>(Back)</p>
</th>
<th className="md:p-5 p-1 text-sm text-black bg-table_row-cream border border-table_border">
LAY <p>(lay)</p>
</th>
<th className="md:p-5 p-1 text-sm" colSpan="2"></th>
</tr>
</thead>
<tbody>
<tr className="md:p-5 p-1 text-sm border border-table_border text-center">
<td className="bg-gray-300 md:p-5 p-1 text-sm">
{data.values[0].val1 === null ? "-" : data.values[0].val1}
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
-<p>(-)</p>
</td>
<td
dataTitle={data.values[0].odds}
className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border "
onClick={(e) => {
console.log(e.target.innerHTML);
setTeam1Back(e.target.innerHTML);
console.log("team1Back", team1Back);
}}
>
{data.values[0].odds === null ? "-" : data.values[0].odds}
</td>
{/* {!data.values.odds && (
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
0<p>(-)</p>
</td>
)} */}
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border ">
{data.values[0].val2 === null ? 0 : data.values[0]?.val2}
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border ">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border ">
-<p>(-)</p>
</td>
</tr>
{data.values[1] && (
<tr className="md:p-5 p-1 text-sm border border-table_border text-center">
<td className="bg-gray-300 md:p-5 p-1 text-sm">
{data.values[1]?.val1}
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
-<p>(-)</p>
</td>
<td
className="md:p-5 p-1 odd:bg-table_row-cream text-sm bg-table_row-blue border border-table_border"
onClick={(e) => SetDrawBack(e.target.value)}
>
{data.values[1]?.odds}
</td>
<td
className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border"
onClick={(e) => SetDrawLay(e.target.value)}
>
{data.values[1]?.val2 === null && "0"}
{data.values[1]?.val2 && data.values[1]?.val2}
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border">
-<p>(-)</p>
</td>
</tr>
)}
{data?.values[2] && (
<tr className="md:p-5 p-1 text-sm border border-table_border text-center">
<td className="bg-gray-300 md:p-5 p-1 text-sm">
{data?.values[2] && data.values[2]?.val1}
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
-<p>(-)</p>
</td>
<td
className="md:p-5 p-1 odd:bg-table_row-cream text-sm bg-table_row-blue border border-table_border"
onClick={(e) => setTeam2Back(e.target.value)}
>
{data?.values[2] && data.values[2]?.odds}
</td>
<td
className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border"
onClick={(e) => setTeam2Lay(e.target.value)}
>
{data.values[2]?.val2 === null && "0"}
{data.values[2]?.val2 && data.values[2]?.val2}
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border">
-<p>(-)</p>
</td>
</tr>
)}
</tbody>
</table>
</>
);
};
export default MatchBetTable;
i want the values in state like i used Team1Back and Team1Lay...and pass it to the placeBet Component after clicking particular row...

Cant you do something like this?
<>
{data.values.map((bet) => (
<tr className="md:p-5 p-1 text-sm border border-table_border text-center">
<td className="bg-gray-300 md:p-5 p-1 text-sm">{bet?.val1}</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-blue border border-table_border ">
-<p>(-)</p>
</td>
<td
className="md:p-5 p-1 odd:bg-table_row-cream text-sm bg-table_row-blue border border-table_border"
onClick={(e) => SetDrawBack(e.target.value)}
>
{bet?.odds}
</td>
<td
className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border"
onClick={(e) => SetDrawLay(e.target.value)}
>
{bet.val2 === null && "0"}
{bet.val2 && bet?.val2}
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border">
-<p>(-)</p>
</td>
<td className="md:p-5 p-1 text-sm bg-table_row-cream border border-table_border">
-<p>(-)</p>
</td>
</tr>
))}
</>

Use .map instead of data[0], data[1]... then add onClick to row and pass whole object from map

Related

Why isn't col-span spanning the full table width

This is my table code, using React and Tailwind CSS. There is one peculiarity: when col-span turns 8, it works as expected. But when it turns 12, it breaks.
I want the table to expand to 12 cols, but it only expands to 10. If I use 11 or 12 it goes to 1, no matter what I used for colspan.
<div className={`flex flex-col lg:col-span-${order.smopen ? 8 : 12}`}>
<div className="overflow-x-auto">
<div className="align-middle inline-block min-w-full">
<div className="shadow overflow-hidden border-b border-gray-200">
<table
className={`min-w-full divide-y divide-gray-200 lg:col-span-${
order.smopen ? 8 : 12
}`}
>
<thead
className={`min-w-full divide-y divide-gray-200 lg:col-span-${
order.smopen ? 8 : 12
}`}
>
<tr>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Тема
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Дедлайн
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Статус
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Сумма
</th>
</tr>
</thead>
<tbody
className={`min-w-full divide-y divide-gray-200 lg:col-span-${
order.smopen ? 8 : 12
}`}
>
{orders.map((order, orderIdx) => (
<tr
onClick={() =>
orderDispatch({
type: "selected",
payload: {
smopen: true,
title: order.title,
dateDeadline: new Date(order.dateDeadline).toLocaleString(
"ru-RU",
{
year: "numeric",
month: "long",
day: "numeric",
}
),
status: order.status,
sum: order.sum,
},
})
}
key={order.id}
className={
orderIdx % 2 === 0
? "bg-white hover:bg-gray-100 cursor-pointer transition-all ease-in-out"
: "transition-all ease-in-out cursor-pointer bg-gray-50 hover:bg-gray-100"
}
>
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
{order.title}
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{new Date(order.dateDeadline).toLocaleString("ru-RU", {
year: "numeric",
month: "long",
day: "numeric",
})}
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{orderTypeSwitch(order.status)}
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{order.sum} ₽
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>;
How can I fix this to have my table span the whole 12 columns?

How to make table header display once in map function in React JS?

I'm displaying data in a tabular format in UI using React and TailwindCSS. I am using a map function to display the data. I am able to display the data but the header is being displayed after each row as they are iterated in a loop.
Please let me know how can I display the output in tabular format with header being displayed only once?
React JS code:
{data && toggle ? (
<div className="table-container">
{data.map((project, idx) => {
return (
<>
<div className="overflow-x-none flex items-center justify-center w-fit mx-auto border border-[#1B71E8]">
<table className="table-fixed max-w-screen-lg border-seperate border-spacing">
<thead>
<tr>
<th>name</th>
<th>country</th>
<th>carbon credits</th>
<th>type</th>
<th>vintage</th>
<th>serial number</th>
</tr>
</thead>
<tbody>
<tr>
<td className="w-52 h-8 text-center">
{project.project.name}
</td>
<td className="w-52 text-center">
{project.project.country}
</td>
<td className="w-32 max-h-2 text-center">
{project.number_of_credits}
</td>
<td className="w-52 text-center">
{project.project.type}
</td>
<td className="w-52 text-center">
{project.vintage}
</td>
<td className="w-52 text-center">
{project.serial_number}
</td>
</tr>
</tbody>
</table>
</div>
</>
);
})}
</div>
table
Can you please help.
Move the element outside of the {data.map(...)} loop. You can also move the element outside of the loop and use the map function to generate the rows inside of it:
{data && toggle ? (
<div className="table-container">
<div className="overflow-x-none flex items-center justify-center w-fit mx-auto border border-[#1B71E8]">
<table className="table-fixed max-w-screen-lg border-seperate border-spacing">
<thead>
<tr>
<th>name</th>
<th>country</th>
<th>carbon credits</th>
<th>type</th>
<th>vintage</th>
<th>serial number</th>
</tr>
</thead>
<tbody>
{data.map((project, idx) => {
return (
<tr>
<td className="w-52 h-8 text-center">
{project.project.name}
</td>
<td className="w-52 text-center">
{project.project.country}
</td>
<td className="w-32 max-h-2 text-center">
{project.number_of_credits}
</td>
<td className="w-52 text-center">
{project.project.type}
</td>
<td className="w-52 text-center">
{project.vintage}
</td>
<td className="w-52 text-center">
{project.serial_number}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
)}

validateDOMNesting(...): <td> cannot appear as a child of <tbody>. even the Structure is ok

The structure is ok but I do get this error
But I dont have any <td> inside <tbody> only <td>s inside <tr>
my code is
<table className="min-w-full divide-y divide-gray-200 ">
<thead className="bg-gray-100">
<tr>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<input
onChange={(e) => {
setAllChecked(!allChecked);
setData(data.map(item => {
return {...item, isChecked: !allChecked}
}))
if (allChecked) {
setSelectedRows([])
} else if (!allChecked) {
setSelectedRows(data);
}
}}
checked={allChecked}
id="remember-me"
name="remember-me"
type="checkbox"
className="h-4 w-4 text-red-600 focus:ring-red-500 border-gray-300 rounded"
/>
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Product Name / Product id
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Product Category
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Brand
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Price
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Stock
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Status
</th>
<th scope="col" className="relative px-6 py-3">
<span className="sr-only">Action</span>
</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{data.length > 0 ? <>
{data.map((product) => (
<tr
className={`${data.indexOf(product) % 2 === 0 ? 'bg-gray-50' : 'bg-white'}`}
key={product.id}>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<input
onChange={() => {
setData(data.map((item) => {
if (item.id === product.id) {
item.isChecked = !item.isChecked;
}
return item;
}));
setSelectedRows(data.filter((item) => item.isChecked));
}}
checked={product.isChecked}
id="remember-me"
name="remember-me"
type="checkbox"
className="h-4 w-4 text-red-600 focus:ring-red-500 border-gray-300 rounded"
/>
</td>
<td className="px-6 pl-2 py-4 whitespace-nowrap">
<div className="flex items-center">
<div className="ml-4">
<div
className="text-sm font-medium text-gray-900">{product.name.length > 20 ? product.name.slice(0, 20) + '...' : product.name}</div>
<div className="text-sm text-gray-500">{product.id}</div>
</div>
</div>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<div className="flex items-center">
<div className="ml-4">
<div
className="text-sm font-medium text-gray-900">{product.category}</div>
<div
className="text-sm text-gray-500">{product.mainProductCategory}</div>
</div>
</div>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<div className="text-sm text-gray-900">{product.brand}</div>
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">$ {product.price}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{product.stock}</td>
<td className="px-6 py-4 whitespace-nowrap">
{product.isPublished ? <>
<span
className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">Published</span></>
: <>
<span
className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">Not Published</span>
</>}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<span className="relative z-0 inline-flex shadow-sm rounded-md">
<button
onClick={(x) => {
changePublishedStatus(product.id, !product.isPublished)
}}
type="button"
className={`relative inline-flex items-center py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-red-500 focus:border-red-500 ${product.isPublished ? 'px-4' : 'px-6'}`}
>
{product.isPublished ? 'Unpublish' : 'Publish'}
</button>
<button
type="button"
className="-ml-px relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-red-500 focus:border-red-500"
>
Edit
</button>
<button
onClick={() => {
deleteProduct(product.id)
}}
type="button"
className="-ml-px relative inline-flex items-center px-4 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-red-500 focus:border-red-500 "
>
Delete
</button>
</span>
</td>
</tr>
))}
</> : <>
<tr>
<td></td>
<td></td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<span
className="inline-flex items-center px-2.5 py-0.5 rounded-md text-sm font-medium bg-red-100 text-red-800">
No results found. Please refine your search or add Products.
</span>
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</>}
</tbody>
</table>
how to fix this

Adding new line of multiple value React JS

I want to add a new line of string to the map function.
My code looks like this :
<tbody>
{" "}
{dataTable.map((table) => {
return (
<tr key={table.id}>
<th className="border-t-0 px-6 align-middle border-l-0 py-4 pt-4 pb-0 text-left flex items-center">
<Avatar name={table.title} size={30} round="25px" className="mr-2" color="#f9fbff" fgColor="#4987f3" />
<span className={"ml-3 font-bold light"}>{table.title} </span>{" "}
</th>{" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> {table.id} </td> {" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> {table.footer} </td>{" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> {table.description} </td> {" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> <i className="fas fa-circle text-emerald-500 mr-2"></i>{" "} {table.tags} </td>{" "}
</tr>
);
})}{" "}
</tbody>
for tags data, there is some value, and I want to add a new line for the value of every tag.
For the data :
[
{
"id": 936556,
"category": 7,
"title": "Gorgeous Cotton Fish",
"description": "The Apollotech B340 is an affordable wireless mouse with reliable connectivity, 12 months battery life and modern design",
"footer": "Gorgeous"
},
{
"id": 874754,
"category": 8,
"title": "Unbranded Plastic Fish",
"description": "The Football Is Good For Training And Recreational Purposes",
"footer": "Practical",
"tags": [
"Music",
"Kids",
"Books",
"Clothing",
"Baby"
],
"createdAt": "2021-09-10T01:39:35.109073+00:00"
},
]
I think you need one more map() specifically for that one property. You can then use something like a <p> tag or maybe a <span> to show your data.
<tbody>
{" "}
{dataTable.map((table) => {
return (
<tr key={table.id}>
<th className="border-t-0 px-6 align-middle border-l-0 py-4 pt-4 pb-0 text-left flex items-center">
<Avatar name={table.title} size={30} round="25px" className="mr-2" color="#f9fbff" fgColor="#4987f3" />
<span className={"ml-3 font-bold light"}>{table.title} </span>{" "}
</th>{" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> {table.id} </td> {" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> {table.footer} </td>{" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> {table.description} </td> {" "}
<td className="border-t-0 px-6 border-l-0 py-4 pt-4 pb-0"> {table.tags.map((x) => <p><i className="fas fa-circle text-emerald-500 mr-2"></i>{" "} {x}</p>{" "} );}
</td>{" "}</tr>
);
})}{" "}
</tbody>

How to increase height of a table cell if the content overflows

I'm coding a credit log system in react using firebase realtime database. I have something like this:
and I'd like to have it so that when the content is really long it doesn't result in a scroll bar but rather causes the height of the cell to increase. I've tried doing some messing around but I'm not so proficient in tailwind. I've attached the code below.
import React, {useState, useEffect} from "react";
import PropTypes from "prop-types";
import firebase from "Firebase"
import TableDropdown from "components/Dropdowns/TableDropdown.js";
// Todo: Make this more module through adding component/variable for each cell
export default function MyCreditLog({ color }) {
const [creditData, setCreditData] = useState([]);
useEffect(() => {
let ref = firebase.database().ref("/creditlogs/"+firebase.auth().currentUser.uid)
console.log(firebase.auth().currentUser.uid)
ref.on("value", snapshot => {
const state = snapshot.val()
setCreditData(Object.values(state))
console.log(state)
})
}, [])
return (
<>
<div
className={
"relative flex flex-col min-w-0 break-words w-full mb-6 shadow-lg rounded " +
(color === "light" ? "bg-white" : "bg-blue-900 text-white")
}
>
<div className="rounded-t mb-0 px-4 py-3 border-0">
<div className="flex flex-wrap items-center">
<div className="relative w-full px-4 max-w-full flex-grow flex-1">
<h3
className={
"font-semibold text-lg " +
(color === "light" ? "text-gray-800" : "text-white")
}
>
My Credit Log
</h3>
</div>
</div>
</div>
<div className="block w-full overflow-x-auto">
{/* Projects table */}
<table className="items-center w-full bg-transparent border-collapse">
<thead>
<tr className="overflow-x-hidden">
<th
className={
"px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-no-wrap font-semibold text-left " +
(color === "light"
? "bg-gray-100 text-gray-600 border-gray-200"
: "bg-blue-800 text-blue-300 border-blue-700")
}
>
Date
</th>
<th
className={
"px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-no-wrap font-semibold text-left " +
(color === "light"
? "bg-gray-100 text-gray-600 border-gray-200"
: "bg-blue-800 text-blue-300 border-blue-700")
}
>
Time In
</th>
<th
className={
"px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-no-wrap font-semibold text-left " +
(color === "light"
? "bg-gray-100 text-gray-600 border-gray-200"
: "bg-blue-800 text-blue-300 border-blue-700")
}
>
Time Out
</th>
<th
className={
"px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-no-wrap font-semibold text-left " +
(color === "light"
? "bg-gray-100 text-gray-600 border-gray-200"
: "bg-blue-800 text-blue-300 border-blue-700")
}
>
Type
</th>
<th
className={
"px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-no-wrap font-semibold text-left " +
(color === "light"
? "bg-gray-100 text-gray-600 border-gray-200"
: "bg-blue-800 text-blue-300 border-blue-700")
}
>
Description
</th>
<th
className={
"px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-no-wrap font-semibold text-left " +
(color === "light"
? "bg-gray-100 text-gray-600 border-gray-200"
: "bg-blue-800 text-blue-300 border-blue-700")
}></th>
</tr>
</thead>
<tbody>
{/* loop through fetched credit data and add rows */}
{creditData.map((credit, index) => {
return (<tr key={index}>
<th className="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-no-wrap p-4 text-left flex items-center">
{credit.date}
</th>
<td className="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-no-wrap p-4">
{credit.timeIn}
</td>
<td className="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-no-wrap p-4">
{credit.timeOut}
</td>
<td className="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-no-wrap p-4">
{credit.type}
</td>
<td className="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-no-wrap p-4">
{credit.description}
</td>
<td className="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-no-wrap p-4 text-right">
<TableDropdown />
</td>
</tr>)
})}
</tbody>
</table>
</div>
</div>
</>
);
}
MyCreditLog.defaultProps = {
color: "light",
};
MyCreditLog.propTypes = {
color: PropTypes.oneOf(["light", "dark"]),
};
What a stupid question. I removed the "whitespace-no-wrap" class from each element and it worked perfectly.

Resources