Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- class ButtonToClick extends React.Component {
- handleClick = () => {
- if (typeof this.props.fn === 'function') {
- this.props.fn();
- }
- }
- render() {
- return <button onClick={this.handleClick}>Klik</button>
- }
- }
- export default class ButtonCounter extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- counter: 0
- }
- }
- increment = () => {
- this.setState({
- counter: this.state.counter + 1
- });
- }
- render() {
- return (
- <div>
- <h1>{this.state.counter}</h1>
- <ButtonToClick fn={this.increment}/>
- <ButtonToClick fn={this.increment}/>
- </div>
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement