简体   繁体   English

TypeError: react__WEBPACK_IMPORTED_MODULE_1___default 不是 function 或其返回值不可迭代

[英]TypeError: react__WEBPACK_IMPORTED_MODULE_1___default is not a function or its return value is not iterable

I'm trying to use useState in functional component in react framework.我正在尝试在反应框架的功能组件中使用 useState 。 But I am getting this error.但我收到了这个错误。 What would be the reason?原因是什么?

App.js应用程序.js

import useState from 'react';
import Header from './components/Header';
import TodoList from './components/TodoList';
import Form from './components/Form';

function App() {

  const [todos, setTodos] = useState({ id: 1, todo: "Todo1" }, { id: 2, todo: "Todo2" });
  return (
    <div className="row justify-content-center">
      <div className="col-lg-6 col-md-7 col-9">
        <Header />
        <Form onClick={() => setTodos()} />
        <TodoList todos={todos} />

      </div>
    </div>
  );
}

export default App;

TodoList.js: TodoList.js:

import ListItem from './TodoListItem';
export default function TodoList(props) {
    return (
        <div>
            {props.todos.map((todo) => <ListItem todo={todo} />)}
        </div>
    )
}

TodoListItem.js TodoListItem.js

import styles from '../sass/todoListItem.module.scss';
export default function TodoListItem({ todo }) {
    return (
        <div className={`card ${styles.title}`}>
            {todo}
        </div>
    )
}

enter image description here在此处输入图像描述

This is because useState is not the default export from the react package.这是因为useState不是react package 的默认导出。

To import specific modules from a package you should use the curly brace syntax.要从 package 导入特定模块,您应该使用花括号语法。 Try using import { useState } from 'react';尝试使用import { useState } from 'react';

More information on import syntax can be found here可以在此处找到有关导入语法的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (WebPack) TypeError: Object is not a function or its return value is not iterable - (WebPack) TypeError: Object is not a function or its return value is not iterable TypeError:__ WWEPACK_IMPORTED_MODULE_0_react ___ default.a.createRef不是函数 - TypeError: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createRef is not a function 未捕获的类型错误:__WEBPACK_IMPORTED_MODULE_0_react___default.a.createContext 不是 function - Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createContext is not a function 类型错误:react__WEBPACK_IMPORTED_MODULE_0___default(...) 不是 function - TypeError: react__WEBPACK_IMPORTED_MODULE_0___default(…) is not a function TypeError:react__WEBPACK_IMPORTED_MODULE_6 ___ default.a.useState不是一个函数 - TypeError: react__WEBPACK_IMPORTED_MODULE_6___default.a.useState is not a function TypeError: react__WEBPACK_IMPORTED_MODULE_0___default.a.createContext is not a function(反应前端,节点后端) - TypeError: react__WEBPACK_IMPORTED_MODULE_0___default.a.createContext is not a function (react frontend, node backend) TypeError:jquery__WEBPACK_IMPORTED_MODULE_7 ___ default(…)(…).daterangepicker不是在将jQuery与react js一起使用时的函数 - TypeError: jquery__WEBPACK_IMPORTED_MODULE_7___default(…)(…).daterangepicker is not a function when using jquery with react js 类型错误:react__WEBPACK_IMPORTED_MODULE_2___default(...) 不是函数。 我该如何解决这个问题? - TypeError: react__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function. How do I solve this? React/Firebase 错误“未捕获(承诺中)TypeError:(0,_firebase__WEBPACK_IMPORTED_MODULE_1__.default)不是函数” - React/Firebase error "Uncaught (in promise) TypeError: (0 , _firebase__WEBPACK_IMPORTED_MODULE_1__.default) is not a function" 类型错误:Webpack 导入的模块不是 function - TypeError: Webpack imported module is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM