Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Wrapper extends React.Component {
- state = {
- count: 0
- };
- // Increase count
- increment = () => {
- const { count } = this.state;
- return this.setState({ count: count + 1 });
- };
- // Decrease count
- decrement = () => {
- const { count } = this.state;
- return this.setState({ count: count - 1 });
- };
- render() {
- const { count } = this.state;
- return (
- <div>
- {this.props.render({
- increment: this.increment,
- decrement: this.decrement,
- count: count
- })}
- {this.props.children()}
- </div>
- );
- }
- };
- export default Wrapper;
- const Habanero = props => <p>{props.children}</p>;
- const Testing = Component => {
- return class extends React.Component{
- constructor(props) {
- super(props);
- }
- getSnapshotBeforeUpdate(prevProps) {
- if (prevProps.odds < this.props.odds) {
- return prevProps.odds - this.props.odds;
- }
- return null;
- }
- componentDidUpdate(prevProps, prevState, snapshot) {
- if (snapshot !== null) {
- console.log(snapshot);
- }
- }
- render() {
- const {odds, ...rest} = this.props;
- return <Component {...rest}>
- <p>{odds}</p>
- </Component>
- }
- }
- };
- const Asd = Testing(Habanero);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement