一些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>
Run Code Online (Sandbox Code Playgroud)
同
$("[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>...`.
Run Code Online (Sandbox Code Playgroud)
是否有推荐的技术将这些插件合并到React组件中?或者它们是否从根本上打破了React的假设并且无法使用它?
我想开始一个同时具有web和reactnative接口的新应用程序.
我决定将所有业务 - 非环境依赖代码转移到第三个包-aka sdk-我可以在两者之间共享反应和反应原生.
所以我的项目现在有4个模块
服务器 - nodejs表达api.
有没有标准的方法来实现这样的结构?
我很可能会喜欢
**面临的挑战**
如何在同时处理sdk和Web模块的同时避免重建步骤?
我目前在我的 React 项目中有一个提供者和上下文设置。上下文扩展了firebase。成分:
import React from 'react';
const FirebaseContext = React.createContext(null);
export const withFirebase = Component => props => (
<FirebaseContext.Consumer>
{firebase => <Component {...props} firebase={firebase} />}
</FirebaseContext.Consumer>
)
export default FirebaseContext;
Run Code Online (Sandbox Code Playgroud)
使用类组件,我可以像这样访问 firebase:
import { withFirebase } from "../components/Firebase";
Run Code Online (Sandbox Code Playgroud)
我的出口是这样的:
export default withFirebase(Admin);
Run Code Online (Sandbox Code Playgroud)
通过这种方式,我可以在我的组件(管理员)中访问this.props.firebase和执行。
我的问题是我有一个功能组件,它是 Admin 的孩子的孩子。管理 -> 子组件 -> 子组件(这是一个)
在这里,我使用与上面相同的导入 withFirebase 并将导出包装在 withFirebase()
const MinistriesAdminForm = props => {
const [ministries, setMinistries ] = useState([]);
useEffect(() => {
this.props.firebase.getMinistries(this.state.currentOrganization).on("value", data => {
const ministriesObject = …Run Code Online (Sandbox Code Playgroud)