如何在其容器中引用反应组件?

时间:2017-08-21 08:34:30

标签: javascript reactjs redux

我有一个喜欢组件的容器。 当onRegionsChange运行时,我需要调用Map的函数。如何实现呢?

import { connect } from 'react-redux'
import Map from './Map'
import { setRegion } from './mapActions'

const map = state => {
  return state.mapReducer.map.data
}

const getRegions = state => {
  return state.mapReducer.map.data.regions
}

const getTypes = state => {
  return state.mapReducer.map.data.types
}

const geo = state => {
  return state.mapReducer.map.app.geo
}

const mapStateToProps = (state) => {
  return {
    geo: geo(state),
    map: map(state),
    regions: getRegions(state),
    types: getTypes(state)
  }
}
const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    onRegionsChange: (region) => {
      console.log('onRegionsChange')
      dispatch(setRegion(region))
    },
    onTypesChange: (navigation) => {
      console.log('onTypesChange')
    }
  }
}

const MapContainer = connect(
  mapStateToProps,
  mapDispatchToProps
)(Map)

export default MapContainer

注意:我无法获得对getWrappedInstance的引用

0 个答案:

没有答案