TypeError: Object(...) is not a function ReactJS + Recoil

TypeError: Object(...) is not a function ReactJS + Recoil

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


atoms.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)
  });

App.js:

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

看来您可能需要从反冲库中销毁 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