Skip to content

Instantly share code, notes, and snippets.

@devarajchidambaram
Created November 22, 2019 09:23
Show Gist options
  • Save devarajchidambaram/e4671247ba4b0e28f2d87d63532a1ddc to your computer and use it in GitHub Desktop.
Save devarajchidambaram/e4671247ba4b0e28f2d87d63532a1ddc to your computer and use it in GitHub Desktop.
React pass value from CHILD => Parent
import React,{Component} from 'react'
import logo from './logo.svg';
import Contact from './Contacts'
class App extends React.Component {
//Pass the callback in the props
constructor(props){
super(props)
this.state = {
contacts : [
{name : 'dev', country : 'india'},
{name : 'Ram', country : 'india'},
{name : 'charan', country : 'india'},
]
}
}
getValueFromContacts(data){
console.log('getValue from contacts================' + data)
}
render() {
return (
<div className="App">
<header className="App-header">
<p>
Learn React
</p>
<Contact contacts={this.state.contacts} cb = {this.getValueFromContacts} />
</header>
</div>
);
}
}
export default App;
class Contacts extends Component{
render(){
const {contacts} = this.props;
console.log('contats', contacts)
setTimeout(()=>{
this.props.cb('12345.............');
}, 5000)
return (
<div className='contact'>
ozzx
</div>
)
}
}
export default Contacts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment