一些 JQuery 插件不仅向 DOM 节点添加行为,而且更改它们。例如,Bootstrap Switch转
<input type="checkbox" name="my-checkbox" checked>
变成类似的东西
<div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-on bootstrap-switch-large bootstrap-switch-animate">
<div class="bootstrap-switch-container">
<span class="bootstrap-switch-handle-on bootstrap-switch-primary">ON</span>
<label class="bootstrap-switch-label"> </label>
<span class="bootstrap-switch-handle-off bootstrap-switch-default">OFF</span>
<input type="checkbox" name="download-version" checked="" data-size="large" data-on-text="3" data-off-text="2.0.1">
</div>
</div>
和
$("[name='my-checkbox']").bootstrapSwitch();
这与 React 不兼容:
Uncaught Error: Invariant Violation: findComponentRoot(..., .0): Unable to find
element. This probably means the DOM was unexpectedly mutated (e.g., by the
browser), usually due to forgetting a <tbody> when using tables or nesting <p> or
<a> tags. ...<omitted>...`.
是否有推荐的技术将这些插件合并到 React 组件中?或者他们是否从根本上打破了 React 的假设并且无法使用它?