I am new to React JS and I want to add onClick
event to my corner cells of the table. So, onClick
I have to add column and row adjacent to the clicked cell.
My table initially consists of 4 column and row respectively. And on click of corner edges a column corresponding to it must be added. For example in the image above if I click on A the column and row will be added as shown. How can I do this ?
import { render } from "@testing-library/react";
import React, { useState, useRef } from "react";
import { Table } from "react-bootstrap";
var MyTable = () => {
let [panel, setPanel] = useState([
["S", "O", "L", "A"],
["R", "P", "A", "N"],
["E", "L", "S", "O"],
["L", "A", "R", "R"],
]);
function renderTable() {
var rows = panel.map(function (item, i) {
var entry = item.map(function (element, j) {
return (
<td id={j}>
{element}
</td>
);
});
return <tr id={i}>{entry}</tr>;
});
return (
<Table>
<tbody>{rows}</tbody>
</Table>
);
}
return <>{renderTable()}</>;
};
export default MyTable;
My code structure something like shown above.