如何使这部分代码适用于新版本的 redux?
这适用于 reudx < 1.0 版本 https://github.com/reactjs/redux/releases/tag/v1.0.0-rc
但现在来自 react-redux
的 Connector
- undefined
有可能使这项工作成功吗?
部分代码
import { Connector } from 'redux/react;
<Connector select={state => ({
center: state.map.get('mapInfo').get('center'),
zoom: state.map.get('mapInfo').get('zoom'),
markers: state.map.get('dataFiltered'),
visibleRowFirst: state.map.get('tableRowsInfo').get('visibleRowFirst'),
visibleRowLast: state.map.get('tableRowsInfo').get('visibleRowLast'),
maxVisibleRows: state.map.get('tableRowsInfo').get('maxVisibleRows'),
hoveredRowIndex: state.map.get('tableRowsInfo').get('hoveredRowIndex'),
openBallonIndex: state.map.get('openBalloonIndex')
})}>
{({dispatch, ...mapProps}) => (
<Map {...mapProps}
{...bindActionCreators(mapActions, dispatch)}
/>
)}
</Connector>
最佳答案
试试这个
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
class Map extends React.Component
{
//Your Map component
}
const mapStateToProps = (state = {}) => {
return {
center: state.map.get('mapInfo').get('center'),
zoom: state.map.get('mapInfo').get('zoom'),
markers: state.map.get('dataFiltered'),
visibleRowFirst: state.map.get('tableRowsInfo').get('visibleRowFirst'),
visibleRowLast: state.map.get('tableRowsInfo').get('visibleRowLast'),
maxVisibleRows: state.map.get('tableRowsInfo').get('maxVisibleRows'),
hoveredRowIndex: state.map.get('tableRowsInfo').get('hoveredRowIndex'),
openBallonIndex: state.map.get('openBalloonIndex')
}
}
const mapDispatchToProps = (dispatch) => {
return {
actions: bindActionCreators(mapActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Map);
关于javascript - React Redux <连接器>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45421622/