-
-
Save johnbeadle/df7d98b6427e2f8d0a3819cf3ca68630 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