mocheng / react-and-redux

《深入浅出React和Redux》代码

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

书本第180页,TodoList链接到了store,但是TodoItem并没有,mapStateToProps为null,不是很理解

lcoder opened this issue · comments

commented

最后的一部分内容:

例如,对于TodoItem组件的单元测试,就可以在JSX中直接这样写,不用Provider:

const subject = <TodoItem store={ store }  { ...otherProps } />
const wrapper = mount( subject )

todoItem第47行代码
看了TodoItem的代码,里面没用到store,书中说这样写是为了:如果被测试的组件并不包含任何其他链接到store的子组件,那就可以直接在组件渲染中用名为store的prop。可被测试的组件如果压根没用到store,那这样子写是为了什么?是connect之后的被链接的组件会取this.props.store吗?这里不是很理解,感谢解答