React&Redux:未捕获的TypeError:(0,_reactRedux.connect)不是函数

时间:2018-07-23 17:52:21

标签: javascript reactjs redux react-redux parceljs

我是reduxreactparceljs的新手。我目前正在通过做redux tutorial来尝试这3种东西。 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()的唯一问题是您不能将其用作装饰器,仅此而已。我想念我不知道的东西吗?

(抱歉我的英语语法不好,不是我的母语)

1 个答案:

答案 0 :(得分:3)

要使用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