3

我是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()是您不能将其用作装饰器,仅此而已。我错过了一些我还不知道的东西吗?

(对不起我的英语语法不好,不是我的第一语言)

4

1 回答 1

5

要使用连接,您需要绑定组件而不是对象。因此,您可以更改待办事项

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
于 2018-07-23T18:01:40.340 回答