Skip to content

Instantly share code, notes, and snippets.

@johnbeadle
Forked from baptistemanson/parent-to-child.js
Created July 13, 2018 08:16
Show Gist options
  • Select an option

  • Save johnbeadle/df7d98b6427e2f8d0a3819cf3ca68630 to your computer and use it in GitHub Desktop.

Select an option

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