Skip to content

Instantly share code, notes, and snippets.

@WDever
Created January 1, 2019 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WDever/0bb1974ddfede1d735813344a005c44d to your computer and use it in GitHub Desktop.
Save WDever/0bb1974ddfede1d735813344a005c44d to your computer and use it in GitHub Desktop.
// App.js
import React, { Component } from 'react';
import Button from './Button';
import './App.css';
class App extends Component {
state = {
num: 0,
}
handleclick = () => {
const { num } = this.state;
console.log(num);
this.setState({
num: num + 1
}, () => alert('update'));
}
render() {
const { num } = this.state;
const { handleclick } = this;
return (
<Button
number={num}
handleclick={handleclick}
/>
);
}
}
export default App;
// Button.js
import React from 'react';
const Button = ({number, handleclick}) => {
return (
<div>
<div
onClick={handleclick}
>
button
</div>
<div>
{number}
</div>
</div>
)
}
export default Button;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment