Last active
December 16, 2019 19:15
-
-
Save dipakkr/a6f27f1c91b9798a50a6d06f313fb302 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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