我是redux
,react
和parceljs
的新手。我目前正在通过做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()
的唯一问题是您不能将其用作装饰器,仅此而已。我想念我不知道的东西吗?
(抱歉我的英语语法不好,不是我的母语)
答案 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