Skip to content

Instantly share code, notes, and snippets.

@dipakkr
Last active December 16, 2019 19:15
Show Gist options
  • Save dipakkr/a6f27f1c91b9798a50a6d06f313fb302 to your computer and use it in GitHub Desktop.
Save dipakkr/a6f27f1c91b9798a50a6d06f313fb302 to your computer and use it in GitHub Desktop.
import React from 'react'
import ListItem from './ListItem';
export class Table extends React.Component {
// Dummy data for the table
state = {
data: tableData
}
getData = (rowData) => {
// This is the row data from ChildComponent
console.log(rowData);
}
render(){
return(
<div>
{this.state.data.map(item => (
<ListItem rowData={item} handleClick={this.getData}/>
))}
</div>
);
}
}
import React from 'react';
const ListItem = (props) => {
return(
// Using Props handleClick as callback function
<div onClick={()=> props.handleClick(props.rowData)}>
<p> {props.rowData.company} </p>
<p> {props.rowData.contact} </p>
<p> {props.rowData.country} </p>
</div>
);
}
export default ListItem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment