【发布时间】:2017-05-12 21:29:27
【问题描述】:
我是 react-redux 的新手,我正在阅读这里的文档 https://github.com/reactjs/react-redux/blob/master/docs/api.md
文档说 connect 定义为:
connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])
但后来我看到了这个示例代码
import React from 'react'
import { connect } from 'react-redux'
import { getData } from '../actions'
class Content extends React.Component {
constructor(props) {
super(props);
}
componentWillMount() {
this.props.dispatch(getData())
}
render() {
const { data } = this.props; //This data is the same returned for fungetStore
return (
<div>
<h1> { data.text } </h1>
</div>
);
}
}
const fungetStore = store => {
return {
data: store //Return the content of the store
}
}
Content = connect(fungetStore)(Content)
export default Content
您可以在代码中看到fungetStore 是在connect 中发送的。但是为什么要这样使用connect呢?不认为您必须定义mapStateToProps 和/或mapDispatchToProps?。我遗漏了文档中的某些内容?
【问题讨论】:
标签: redux react-redux