React and well-designed jquery plugins are not incompatible with the problem.

Source: Internet
Author: User

Copyright belongs to the author.
Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Fluxxu
Links: http://www.zhihu.com/question/36045843/answer/67064767
Source: Know

React and well-designed jquery plugins are not incompatible with the problem.
What I call a well-designed plugin is that you give him an element, and he only operates in this element, not around. There is also the way it provides security destroy that can be called.
In general, for example, you want to use a jquery AutoComplete plugin that you initialize in jquery:
$(‘#input‘).autocomplete();
Inside the react, you wrap it up like this:
React.Createclass({Shouldcomponentupdate(){ReturnFalse;Tell react this component we're going to do it ourselves, don't touch it.},Componentdidmount(){$(this. Getdomnode ()). autocomplete (); }, componentwillunmount () {$< Span class= "P" > (this. Getdomnode ()). autocomplete ( ' destroy ' //call plug-in cleanup function }, render () {return <input type=  "text" />}             
Occasionally have a brain residue plugin, do not want to take a selector string initialization, you can deal with:
var counter = 0;React.createClass({    shouldComponentUpdate() {        return false;    },    componentWillMount() {        this.__elementID = ‘naocan_‘ + (++counter); //强制给他分配一个唯一的id    },    componentDidMount() {        this.__instance = naocan.init({            selector: ‘#‘+this.__elementID        });    },    componentWillUnmount() {        this.__instance.destroy();    },    render() {        return <input id={this.__elementID} type="text" />;    }});

React and well-designed jquery plugins are not incompatible with the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.