尽管有点笨拙,但可以将react与直接操作DOM的库一起使用。你的第一个想法是正确的,因为
Integrating with other libraries
解释如何与jquery集成:
[L]ETS为通用jquery插件绘制了一个包装。
我们将向根dom元素附加一个引用。内部
componentdidmount,我们将得到它的引用,以便将其传递给
jquery插件。
为了防止安装后的反应接触到DOM,我们将返回
render()方法中的空值。元素没有
属性或子级,因此react没有理由更新它,离开
jquery插件可自由管理dom的这一部分:
class SomePlugin extends React.Component {
componentDidMount() {
this.$el = $(this.el);
this.$el.somePlugin();
}
componentWillUnmount() {
this.$el.somePlugin('destroy');
}
render() {
return <div ref={el => this.el = el} />;
}
}