使用Dan Abramov的Redux优秀教程,第27章 - 使用connect()生成容器 - 正在发生一个奇怪的错误:
首先我定义这两个函数:
BETWEEN [southwest lng] and [northeast lng]
然后我导入必要的依赖:
select * from TABLE where
然后我使用react-redux公开的方法创建我的组件,并传入这两个函数,最后连接到我的另一个组件>= [northeast lat] and
。
<= [southwest lat] and
当我这样做时,它会导致浏览器无法呈现并且控制台返回:
>= [southwest lng] and
我之前从未遇到过这个错误,它似乎特定于<= [northeast lng]
的{{1}}方法。
之前是否有人遇到此问题,并且/或知道可能导致此问题的原因?
更新:
上面定义了 const mapStateToProps = (state) => {
return {
todos: getVisibleTodos(state.todos, state.visibilityFilter)
};
}
const mapDispatchToProps = (dispatch) => {
return {
onTodoClick: (id) => {
dispatch({
type: 'TOGGLE_TODO',
id
})
}
}
}
。如果您希望看到import { connect } from 'react-redux'
...
TodoList
答案 0 :(得分:2)
You're probably defining the TodoList
component after your call to connect
. Unlike the var
keyword, the ES6 keywords like let
, const
, and class
do not get hoisted to the top of the scope, and only exist starting at the line they're declared on. So, if you call connect()
before you've defined TodoList
, you're effectively running connect()(undefined)
. It's also possible that you might have an import statement that's not correct, which could also result in TodoList
being undefined.
See https://github.com/reactjs/react-redux/issues/253内的网址,以进行进一步讨论。