javascript - React Redux <连接器>

标签 javascript reactjs redux

如何使这部分代码适用于新版本的 redux? 这适用于 reudx < 1.0 版本 https://github.com/reactjs/redux/releases/tag/v1.0.0-rc 但现在来自 react-reduxConnector - 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/

相关文章:

javascript - Array.fill().map() 在 react 中不起作用

javascript - react Hook : Handling Objects as dependency in useEffects

Javascript 对象而不是 Redux?

javascript - Prisma 3 关系聚合(求和)

javascript - JS 代码加载样式表。如何修改JS,在html中引用样式表?

reactjs - React UseState boolean 数组修改一个元素

javascript - 当 redux 状态发生变化时,我应该使用哪种 React 循环方法来重新渲染组件?

javascript - 如何使用 ReactJs 中的键从父组件打开子组件模式

javascript - 调用 javascript 原型(prototype)方法时未定义的函数

javascript - 如何检查数据属性是否不包含带有 :contains in jQuery 的字符串