In react js how to fetch api data dynamically on the basis of click button.in my below code i want to fetch data on the basis of click using react js .how can we do that .
https://mocki.io/v1/be3cb19b-bd49-4a82-b19b-44b859e19d5d my api is this.in my below code i make one table and i want when i click on row 1st that is airplane and when i click first row then fetch airplane data using this api https://mocki.io/v1/be3cb19b-bd49-4a82-b19b-44b859e19d5d .
how can we do that.
is there any help.its very thankful.
var TableComponent = React.createClass({
render: function() {
// Data
var dataColumns = this.props.data.columns;
var dataRows = this.props.data.rows;
var tableHeaders = (<thead>
<tr>
{dataColumns.map(function(column) {
return <th>{column}</th>; })}
</tr>
</thead>);
var tableBody = dataRows.map(function(row) {
return (
<tr>
{dataColumns.map(function(column) {
return <td>{row[column]}</td>; })}
</tr>); });
// Decorate with Bootstrap CSS
return (<table className="table table-bordered table-hover" width="100%">
{tableHeaders}
{tableBody}
</table>) }});
// Example Data
var tableData = {
columns: ['Service_Name', 'Cost/Unit'],
rows: [{
'Service_Name': 'airplane',
'Cost/Unit': 50
}, {
'Service_Name': 'cat',
'Cost/Unit': 50
},{
'Service_Name': 'fruits',
'Cost/Unit': 50
}, {
'Service_Name': 'pool',
'Cost/Unit': 50
}]
};
ReactDOM.render(
<TableComponent data = {tableData} />,
document.getElementById('table-component'));