简体   繁体   English

react-google-maps重新组合错误-`not a function`

[英]react-google-maps recompose error - `not a function`

I am getting an error when trying to run a top level defined react-google-maps component. 尝试运行顶级定义的react-google-maps组件时出现错误。 (0 , _reactGoogleMaps.withProps) is not a function

Here is my code ( codesandbox ): 这是我的代码( codesandbox ):

import * as React from 'react'
import {
  withScriptjs,
  withGoogleMap,
  GoogleMap,
  Marker,
  withProps,
  withState,
  withHandlers
} from "react-google-maps";
import { compose } from 'recompose'

var service, refs;
const LocationPicker = compose(
  withProps({
    googleMapURL: "https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,places&key=AIzaSyDnKwHUG_EJXN5EEW6hTftZHYo8E8QTTXY",
    loadingElement: <div style={{ height: `100%` }} />,
    containerElement: <div style={{ height: `400px` }} />,
    mapElement: <div style={{ height: `100%` }} />,
  }),
  withScriptjs,
  withGoogleMap,
  withState('places', '', ''),
  withHandlers(() => {
    refs = {
      map: undefined,
    }

    return {
      onMapMounted: () => ref => {
        refs.map = ref
        service = new google.maps.places.PlacesService(refs.map.context.__SECRET_MAP_DO_NOT_USE_OR_YOU_WILL_BE_FIRED);
      },
    }
  }),
)((props) => {
  return (
    <GoogleMap
      ref={props.onMapMounted}
      defaultZoom={13}
      defaultCenter={{ lat: 42.3570637, lng: -71.06257679999999 }}
    >
      {props.marker &&
        <Marker position={{ lat: props.marker.lat, lng: props.marker.lng }} draggable={true} />
      }
    </GoogleMap>
  )
})



class HomeMap extends Component {
  state = {
    sideBarOpen: true,
    values: [800, 1200]
  }

  render() {
    return (
      <div>
        <div id="map-wrapper">
          <LocationPicker
            googleMapURL="https://maps.googleapis.com/maps/api/js?key=AIzaSyC4R6AN7SmujjPUIGKdyao2Kqitzr1kiRg&v=3.exp&libraries=geometry,drawing,places"
            loadingElement={<div style={{ height: `100%` }} />}
            containerElement={<div style={{ height: `400px` }} />}
            mapElement={<div style={{ height: `100%` }} />}
            lat={42.357527}
            lng={-71.062778}
            marker={this.state.marker}
          />
        </div>
      </div>)
  }
}

Any ideas? 有任何想法吗?

You are importing withProps from react-google-maps . 您正在从react-google-maps导入withProps You should import it from recompose : 您应该从recompose导入它:

import { compose, withProps } from 'recompose';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM