Skip to content

Instantly share code, notes, and snippets.

@lassombra
Last active November 10, 2017 16:25
Show Gist options
  • Save lassombra/60ae3642bb363a2365e267a77eb5fc2f to your computer and use it in GitHub Desktop.
Save lassombra/60ae3642bb363a2365e267a77eb5fc2f to your computer and use it in GitHub Desktop.
jquery react wrapper
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