Skip to content

Instantly share code, notes, and snippets.

@baptistemanson
Created July 9, 2018 15:11
Show Gist options
  • Save baptistemanson/dd3a4b8d55cb072d99774dd066f90c0e to your computer and use it in GitHub Desktop.
Save baptistemanson/dd3a4b8d55cb072d99774dd066f90c0e to your computer and use it in GitHub Desktop.
Bubbling
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