最佳答案
我可能遗漏了一些显而易见的事情我想澄清一下。
我的理解是。
在一个天真的反应组件,我们有 states
和 props
。用 setState
更新 state
会重新呈现整个组件。props
大部分是只读的,更新它们是没有意义的。
在订阅 redux 存储的反应组件中,通过类似于 store.subscribe(render)
的东西,它显然会在每次存储更新时重新呈现。
Response-redux 有一个帮助器 connect()
,它将状态树的一部分(组件感兴趣的部分)和 actionCreators 作为 props
注入到组件中,通常是通过类似
const TodoListComponent = connect(
mapStateToProps,
mapDispatchToProps
)(TodoList)
但是由于了解到 setState
对于 TodoListComponent
对还原状态树变化(重新呈现)作出反应是必不可少的,我在 TodoList
组件文件中找不到任何与 state
或 setState
相关的代码。上面写着:
const TodoList = ({ todos, onTodoClick }) => (
<ul>
{todos.map(todo =>
<Todo
key={todo.id}
{...todo}
onClick={() => onTodoClick(todo.id)}
/>
)}
</ul>
)
有人能告诉我我错过了什么吗?
另外,我在跟随 还原包附带的待办事项列表示例。