如何通過react-redux connect方法訪問傳遞給組件的調度函數?如果我嘗試通過this.props訪問回調。該功能未找到。顯示以下錯誤:所需道具onDataUpdated
在EditTable
和類型錯誤未指定:this.props.onDataUpdated不是一個函數使用react-redux將屬性映射到屬性
ConsumerIDManagement.js
import { connect } from 'react-redux'
var React = require('react');
var EditTable = require("../components/EditTable");
const ConsumerIDEditTable = connect(
mapDispatchToProps
)(EditTable)
const mapDispatchToProps = (dispatch, ownProps) => {
return {
onDataUpdated: (oldRow,newRow) => {
dispatch({ oldRow: oldRow, newRow: newRow,type: "onRowUpdated"})
}
}
}
<ConsumerIDEditTable data={this.state.data} editableColumns={["consumerID"]}/>
EditTable.js
var React = require('react');
var ReactDataGrid = require('react-data-grid');
var ResultFormatter = require("../components/ResultFormatter");
var EditTable = React.createClass({
propTypes: {
onDataUpdated: React.PropTypes.func.isRequired
},
...
handleRowUpdated : function(e){
var rows = this.state.rows;
// inform dispatcher of changed data
this.props.onDataUpdated(rows, e.updated);
},
...
},
render:function(){
return (
<ReactDataGrid
...
onRowUpdated={this.handleRowUpdated} />
)
}
});
module.exports = EditTable;
把它當作第二個參數不利於 常量ConsumerIDEditTable =連接( 空,mapDispatchToProps )(EditTable) –
您還聲明'mapDispatchToProps'與'const'使用後。 –