我想從我的智能組件中調度一個動作。我試過使用mapDispatchToProps
和this.props.dispatch(actions.getApplications(1))
,但都沒有將這些操作綁定到props
。This.props.dispatch不是函數 - React-Redux
林不知道是否因爲我的mapStateToProps
不包括在內?我試圖包括它,但它也沒有工作。
任何幫助表示讚賞,我道歉的代碼塊的長度下面。
import classNames from 'classnames';
import SidebarMixin from 'global/jsx/sidebar_component';
import Header from 'common/header';
import Sidebar from 'common/sidebar';
import Footer from 'common/footer';
import AppCard from 'routes/components/appCard';
import { getApplications } from 'redux/actions/appActions';
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import actions from 'redux/actions';
import { VisibilityFilters } from 'redux/actions/actionTypes';
class ApplicationContainer extends React.Component {
constructor(props){
super(props)
this.state = {
applicants: []
}
this.onDbLoad = this.onDbLoad.bind(this)
}
onDbLoad(){
console.log(this.props.dispatch)
// this.props.getApplications(1)
}
render() {
return (
<Col sm={12} md={4} lg={4}>
<PanelContainer style={panelStyle}>
<Panel>
<PanelBody >
<Grid>
<Row>
{ this.onDbLoad() }
</Row>
</Grid>
</PanelBody>
</Panel>
</PanelContainer>
</Col>
)}
}
function mapDispatchToProps(dispatch){
return bindActionCreators({ getApplications: getApplications },dispatch)
}
export default connect(null, mapDispatchToProps)(ApplicationContainer);
@SidebarMixin
export default class extends React.Component {
render() {
const app = ['Some text', 'More Text', 'Even More Text'];
var classes = classNames({
'container-open': this.props.open
})
return (
<Container id='container' className={classes}>
<Sidebar />
<Header />
<Container id='body'>
<Grid>
<Row>
<ApplicationContainer />
</Row>
</Grid>
</Container>
<Footer />
</Container>
)}
}
感謝您的快速響應,我已經嘗試過您的解決方案,但派送仍然不會顯示爲「道具」。 – richTheCreator
你是否特別想使用'dispatch'?或者你想讓你的其他行動受到約束。如果前者,我可以更新答案。 – Interrobang
我想分發一個動作,以便它可以通過減速器。 – richTheCreator