小编Rah*_*mad的帖子

使用在React Components中转换DOM的JQuery插件?

一些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">&nbsp;</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的假设并且无法使用它?

javascript jquery reactjs

47
推荐指数
3
解决办法
3万
查看次数

在create react app Reactjs应用程序中使用常见的Sdk模块共享代码库

我想开始一个同时具有web和reactnative接口的新应用程序.

我决定将所有业务 - 非环境依赖代码转移到第三个包-aka sdk-我可以在两者之间共享反应和反应原生.

所以我的项目现在有4个模块

  1. 网络 - 用cra创建
  2. Sdk - 主要是redux + redux saga +反应容器+ Hoc's
  3. 移动 - 反复原生
  4. 服务器 - nodejs表达api.

    • 所有的网络,移动和服务器都将依赖于Sdk模块.
    • sdk模块将依赖于服务器模块 - 主要是为了暗示模拟和数据接口.

有没有标准的方法来实现这样的结构?

我很可能会喜欢

  • 使用纱线工作区将所有节点模块提升到一个文件夹中,以避免在每个项目中重新安装包
  • 我将同时在所有4个项目中工作,所以我需要hotreload才能意识到这一点.

**面临的挑战**

  1. Cra不会在src文件夹之外转换代码,所以虽然web项目确实刷新,但是我在sdk上做了更改.它无法理解es6代码.
  2. Jest也不了解node_modules中的es6

如何在同时处理sdk和Web模块的同时避免重建步骤?

babel reactjs react-native create-react-app monorepo

16
推荐指数
2
解决办法
492
查看次数

无法从功能组件访问道具

我目前在我的 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)

reactjs react-hooks

0
推荐指数
1
解决办法
423
查看次数