Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from "react";
- import ReactDOM from "react-dom";
- import debounce from "lodash.debounce";
- const TestFunc = ({ count, onClick }) => {
- const handleClick = debounce(() => {
- onClick();
- console.log(count);
- }, 500);
- return (
- <div>
- <button type="button" onClick={handleClick}>
- Func: {count}
- </button>
- </div>
- );
- };
- class TestClass extends React.Component {
- handleClick = debounce(() => {
- this.props.onClick();
- console.log(this.props.count);
- }, 500);
- render() {
- return (
- <div>
- <button type="button" onClick={this.handleClick}>
- Class: {this.props.count}
- </button>
- </div>
- );
- }
- }
- const App = () => {
- const [countClass, setCountClass] = React.useState(0);
- const [countFunc, setCountFunc] = React.useState(0);
- return (
- <div>
- <TestFunc count={countFunc} onClick={() => setCountFunc(countFunc + 1)} />
- <TestClass
- count={countClass}
- onClick={() => setCountClass(countClass + 1)}
- />
- </div>
- );
- };
- ReactDOM.render(<App />, document.getElementById("root"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement