I want to make nested component clickable and to know on which component is clicked.
I had tried to send variable but there are some issues.
If I write function with this.clickMe() it will be invoked at component load.
if the function is written in this way this.clickMe without rounded brackets, the click event is invoked but I can not pass a parameter.
import React, { Component } from 'react';
import CategoryControlRow from './components/CategoryControlRow';
import './style.css';
/**
* @class ./widgets/SeatMap/components/LeafletMap/components/CategoryControl
*/
class CategoryControl extends Component
{
/**
* TODO: This function supposed to be deleted.
*/
clickMe = (text) =>
{
alert(text);
};
/**
* @returns {XML}
*/
render()
{
return (
<div className="col-xs-12 col-md-3" id="categories">
<p className="text-uppercase" id="filter">Ansicht Filtern</p>
<CategoryControlRow class={'category purple'} clickMe={this.clickMe} categoryName={'1. Kategorie'} currency={'CHF'} value={"78.00"} />
<CategoryControlRow class={'category orange'} clickMe={this.clickMe} categoryName={'2. Kategorie '} currency={'CHF'} value={"68.00"} />
<CategoryControlRow class={'category green'} clickMe={this.clickMe} categoryName={'3. Kategorie'} currency={'CHF'} value={"58.00"} />
<CategoryControlRow class={'category blue'} clickMe={this.clickMe} categoryName={'4. Kategorie'} currency={'CHF'} value={"48.00"} />
</div>
)
}
}
export default CategoryControl;
Sub Component
import React, { Component } from 'react';
import './style.css';
/**
* @class ./widgets/SeatMap/components/LeafletMap/components/CategoryControl/components/CategoryControlRow
*/
class CategoryControlRow extends Component
{
/**
* @returns {XML}
*/
render() {
return (
<p className={"category " + this.props.class} onClick={this.props.clickMe}>
{this.props.categoryName}
<span>
{this.props.currency} {this.props.value}
</span>
</p>
)
}
}
export default CategoryControlRow;