javascript - React & Redux: Uncaught TypeError: (0 , _reactRedux.connect) 不是函数
问题描述
我是redux
,react
和的新手parceljs
。我目前正在通过redux tutorial
. 在parceljs
完成它之后,当我进入浏览器时,我在控制台上收到了这个错误:
Uncaught TypeError: (0 , _reactRedux.connect) is not a function
现在的代码是
import { connect } from 'react-redux';
const AddTodo = ({dispatch}) => {
.
.
.
}
export default connect()(AddTodo)
我变了:
import { connect } from 'react-redux';
到:
import { connect } from 'redux';
并给了我基本相同的错误。
在这种情况下我该怎么办?
我检查了文档和问题,我发现的唯一问题connect()
是您不能将其用作装饰器,仅此而已。我错过了一些我还不知道的东西吗?
(对不起我的英语语法不好,不是我的第一语言)
解决方案
要使用连接,您需要绑定组件而不是对象。因此,您可以更改待办事项
const AddTodo = {
和:
const AddTodo = () => { // a stateless component
// now, you can return the object
return ( // just an example
<div>
<input type="text" />
</div>
)
}
并且连接是从 react-redux 导入的:
import { connect } from 'react-redux'; // this is correct
推荐阅读
- laravel - Laravel Valet 和 wordpress 子文件夹安装
- sql - 从 Oracle 中每个给定的当前日期开始滚动 7 个日历日期
- javascript - can someone explain me this logic in redux-form validation?
- reporting-services - 使用表达式在报表服务器中的 SSRS 中钻取
- spring-boot - 通过工厂方法进行 Bean 实例化失败
- angularjs - AngularJS:在指令后插入模板中的字符串
- javascript - 将数据发送到该 servlet 后,如何使用 ajax 从 servlet 获得响应?
- java - 数组列定位和不停的do...while循环
- angular - Promise returned from onSearch(),onSearchButtonClick() is ignored
- python - Using Python Click within a class