Last active
November 10, 2017 16:25
-
-
Save lassombra/60ae3642bb363a2365e267a77eb5fc2f to your computer and use it in GitHub Desktop.
jquery react wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default class Wrapper extends React.Component { | |
shouldComponentUpdate() { | |
// very important. You never rerender, instead use component did receive props and update your jquery plugin | |
return false; | |
} | |
safeRender() { | |
return <div className="some-class-that-matters" ref={element => this.wrapper = element}></div>; | |
componentDidMount() { | |
$(this.wrapper).library(); | |
} | |
componentDidReceiveProps(props) { | |
$(this.wrapper).library(updatePropsFunc) | |
} | |
componentWillUnmount() { | |
$(this.wrapper).library(cleanupFunc) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment