Jos*_*edo 3 javascript reactjs redux react-redux parceljs
我是新来的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)
Run Code Online (Sandbox Code Playgroud)
我变了:
import { connect } from 'react-redux';
到:
import { connect } from 'redux';
并给了我基本相同的错误。
在这种情况下我该怎么办?
我检查了文档和问题,我发现的唯一问题connect()是您不能将它用作装饰器,仅此而已。我是否遗漏了一些我还不知道的东西?
(对不起,我的英语语法不好,不是我的母语)
要使用连接,您需要绑定组件而不是对象。因此,您可以更改您的待办事项
const AddTodo = {
Run Code Online (Sandbox Code Playgroud)
和:
const AddTodo = () => { // a stateless component
// now, you can return the object
return ( // just an example
<div>
<input type="text" />
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
并且连接是从 react-redux 导入的:
import { connect } from 'react-redux'; // this is correct
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9140 次 |
| 最近记录: |