Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Wrapper extends React.Component {
  2.     state = {
  3.         count: 0
  4.     };
  5.  
  6.     // Increase count
  7.     increment = () => {
  8.         const { count } = this.state;
  9.         return this.setState({ count: count + 1 });
  10.     };
  11.  
  12.     // Decrease count
  13.     decrement = () => {
  14.         const { count } = this.state;
  15.         return this.setState({ count: count - 1 });
  16.     };
  17.  
  18.     render() {
  19.         const { count } = this.state;
  20.  
  21.         return (
  22.             <div>
  23.                 {this.props.render({
  24.                     increment: this.increment,
  25.                     decrement: this.decrement,
  26.                     count: count
  27.                 })}
  28.                 {this.props.children()}
  29.             </div>
  30.         );
  31.     }
  32. };
  33.  
  34. export default Wrapper;
  35.  
  36. const Habanero = props => <p>{props.children}</p>;
  37.  
  38.     const Testing = Component => {
  39.         return class extends React.Component{
  40.             constructor(props) {
  41.                 super(props);
  42.             }
  43.  
  44.             getSnapshotBeforeUpdate(prevProps) {
  45.                 if (prevProps.odds < this.props.odds) {
  46.                     return prevProps.odds - this.props.odds;
  47.                 }
  48.  
  49.                 return null;
  50.             }
  51.  
  52.             componentDidUpdate(prevProps, prevState, snapshot) {
  53.                 if (snapshot !== null) {
  54.                     console.log(snapshot);
  55.                 }
  56.             }
  57.  
  58.             render() {
  59.                 const {odds, ...rest} = this.props;
  60.  
  61.                 return <Component {...rest}>
  62.                     <p>{odds}</p>
  63.                 </Component>
  64.             }
  65.         }
  66.     };
  67.  
  68.     const Asd = Testing(Habanero);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement