首页 > 解决方案 > TypeError: Object(...) is not a function ReactJS + Recoil

问题描述

我正在使用 ReactJs 和 Recoil。导出原子并将其导入 App.js 时,我得到一个 TypeError: Object (...) is not a function,这是什么问题?


原子.js:

    import atom from 'recoil';

    export const textState = atom({
    key: 'textState', // unique ID (with respect to other atoms/selectors)
    default: '', // default value (aka initial value)
  });

应用程序.js:

import {
  useRecoilState, atom
} from 'recoil';
import { textState } from "./atoms"

标签: javascriptreactjsrecoiljs

解决方案


看起来您可能需要atom从反冲库中销毁

尝试将您的导入更改为如下所示:

import { atom } from 'recoil'

他们的文档中的更多信息: https ://recoiljs.org/docs/introduction/getting-started

详细了解 JavaScript 中的解构:https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment


推荐阅读