我试图将以下demo.js类组件here转换为here(demo.js)以上的功能组件,当我试图进行更改时,收到错误:

未定义immutableTree

任何帮助都会很好.

推荐答案

让我们详细判断一下你的第131-144行:

const onChange = (immutableTree, config) => {
    immutableTree = immutableTree; // <-- why are you assigning the same var to itself?
    config = config;  // <-- why are you assigning the same var to itself?
    updateResult(); // <-- you are not passing any variables here

    const jsonTree = getTree(immutableTree);
    const { logic, data, errors } = jsonLogicFormat(immutableTree, config);
  };

  const updateResult = throttle(() => {
    setState({ tree: immutableTree, config: config }); // <-- but here you expect variables to be used
  }, 100);

解决方案是:

更正版本:

 const onChange = (immutableTree, config) => {
    updateResult(immutableTree, config);

    const jsonTree = getTree(immutableTree);
    const { logic, data, errors } = jsonLogicFormat(immutableTree, config);
  };

  const updateResult = throttle((immutableTree, config) => {
    setState({ tree: immutableTree, config });
  }, 100);

Reactjs相关问答推荐

react应用程序中的字体不适用于.scss扩展名

URL参数和React路由中的点

使用Thattle和Use Effect setTimeout进行搜索有什么不同

如何在关闭和打开此 Select 输入时应用旋转效果?

Reaction-路由-DOM v6与v5

使用VITE的Reaction应用程序的配置是否正确?

useRef()的钩子调用无效

useEffect不重新渲染

ctx.strokeStyle 在 canvas html 5 中不起作用

React Native - 如何处理错误带有有效负载的NAVIGATE操作..未被任何导航器处理?

如何在屏幕上使用相同的可重用

如何读取 null 的属性?

FlatList 不在 React Native 中呈现项目

如何在react 中正确销毁上下文?

在 React 的父级中多次调用子级时从子级获取数据到父级

Github 页面无法正确呈现 CSS,因为它是本地的

如何在props 更改时运行自定义挂钩?

调用 Jest 和服务方法的问题

为什么我在运行一些 npm react 命令时会收到这些警告?

单击三个按钮之一后如何显示特定按钮的内容?单击其中一个按钮后应隐藏所有按钮