2
I’m using the map to make a list of products, until then quiet, but in the layout there is a dropdown where we will present more information of that item, until then quiet also.
But my problem is that when I open the dropdown of a specific product, it opens the dropdown of all products. I would like to know how to pass a parameter to identify and open only the dropdown of the specific product.
Follow the JSX code snippet:
{this.state.products.map(product => (
<tr className="list-item-row-payment" key={product.id}>
<td>{product.id}</td>
<td>{product.name}</td>
<td>
<div className="itens-acoes">
<button onClick={() => this.showDropdownDoc()}>More</button>
<div className={this.state.DropdownDoc}>
<td>{product.origin}</td>
<td>{product.link}</td>
</div>
</div>
</td>
</tr>
))}
NOTE: I am using CSS with None display to hide through the state.
Function of the dropdown:
showDropdownDoc = () => {
if (this.state.DropdownDoc === "true") {
this.setState({ DropdownDoc: "hide" });
console.log(this.state)
} else {
this.setState({ DropdownDoc: "true" });
}
}
My state:
this.state = {
DropdownDoc: "hide",
}
Convert the code snippet where you render your trs into a New React component. This way you can maintain the state of the dropdown in each child component. <Componentefilho product={product} />
– Jairon Alves Lima