I have three containers in which I am inserting buttons with different names, I need to obtain the name of each button inserted in each container and that everything is inside an array for example:
Rows container: insert the company btn Columns container: insert the soles btn Values container: insert the date btn
The array should be like this: ['company', 'soles', 'date']
My question is: how can I know the name of each button that I insert in each container, without having to click on the container or the button that I am inserting.
import React, { useState } from "react";
import "../assets/styles/Container.css";
import { ReactSortable } from "react-sortablejs";
import ButtonApp from "./ButtonApp";
import { getData } from "../services/api_aralsoft";
const Container = () => {
const [row, setRow] = useState([]);
const [column, setColumn] = useState([]);
const [values, setValues] = useState([]);
return (
<>
<div className="bottomContainer">
<section className="itemsSelected">
<div className="containerVertical">
<div className="containerR">
Filas
<ReactSortable list={row} setList={setRow} group="selectedButton">
{!row
? "Cargando..."
: row.map((item, index) => (
<button className="btnSelect" key={index}>
{item}
</button>
))}
</ReactSortable>
</div>
</div>
<article className="container_col_val">
<div className="containerHorizontal">
<div className="containerR">
Columnas
<ReactSortable
list={column}
setList={setColumn}
group="selectedButton"
>
{!column
? "Cargando..."
: column.map((item, index) => (
<button className="btnSelect" key={index}>
{item}
</button>
))}
</ReactSortable>
</div>
</div>
<div className="containerHorizontal">
<div className="containerR">
Valores
<ReactSortable
list={values}
setList={setValues}
group="selectedButton"
>
{!values
? "Cargando..."
: values.map((item, index) => (
<button className="btnSelect" key={index}>
{item}
</button>
))}
</ReactSortable>
</div>
</div>
</article>
</section>
<section>
<ButtonApp name="Generar Reporte" />
</section>
</div>
</>
);
};
export default Container;
What I think you can do is use the ref callback property that react offers to call a method that inserts into your array the name it receives from the component that was loaded.
It would be something like this: