Created
July 9, 2018 15:11
-
-
Save baptistemanson/dd3a4b8d55cb072d99774dd066f90c0e to your computer and use it in GitHub Desktop.
Bubbling
This file contains hidden or 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, { Component } from "react"; | |
import logo from "./logo.svg"; | |
import "./App.css"; | |
const Child = ({ onClick }) => <button onClick={onClick}>Click me</button>; | |
class Parent extends Component { | |
field = "hello"; | |
handleClick = e => { | |
console.log(this.field, e); | |
}; | |
render() { | |
return <Child onClick={this.handleClick} />; | |
} | |
} | |
class App extends Component { | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<h1 className="App-title">Welcome to React</h1> | |
</header> | |
<Parent /> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment