I'm a beginner with Typescript and very confused. I have a component that uses react-google-maps
where the component is reusable.
Map.tsx
import * as React from 'react';
import { compose, withStateHandlers } from 'recompose';
import { GoogleMap, withGoogleMap } from 'react-google-maps';
const ContactMap: React.ComponentClass<{}> = compose(
withStateHandlers(() => ({
isOpen: false,
// tslint:disable-next-line:align
}), {
onToggleOpen: ({ isOpen }) => () => ({
isOpen: !isOpen,
}),
}),
withGoogleMap,
)(props =>
<div>
<GoogleMap
defaultZoom={props.zoom}
defaultCenter={props.center}
defaultOptions={{
streetViewControl: false,
scaleControl: false,
mapTypeControl: false,
panControl: false,
zoomControl: false,
rotateControl: false,
fullscreenControl: false,
disableDefaultUI: true,
scrollwheel: false,
}}
>
{props.children}
</GoogleMap>,
</div>,
);
export default ContactMap;
And the error is: Property 'zoom' does not exist on type '{ children?: ReactNode; }'.
and I assume it'll do the same for center
.
I've tried something like
interface Props {
containerElement: any;
mapElement: any;
zoom: number;
center: any;
}
And passing that in but that doesn't solve the problem. It returns
Type 'ComponentClass<{}>' is not assignable to type 'ComponentClass<Props>'.
Type '{}' is not assignable to type 'Props'.
Property 'containerElement' is missing in type '{}'.
My component that uses the map:
import * as React from 'react';
import { Map } from '@ecomm/map';
import { InfoWindow, Marker } from 'react-google-maps';
const ContactMap: React.SFC = () => {
return (
<Map
containerElement={<div style={{ height: `400px` }} />}
mapElement={<div style={{ height: `100%` }} />}
center={{
lat: 40.745093,
lng: -73.993048,
}}
zoom={16}
>
<Marker
position={{
lat: 40.745093,
lng: -73.993048,
}}
>
<InfoWindow>
<TextHeader>CHELSEA STUDIO</TextHeader>
</InfoWindow>
</Marker>
</Map>
);
};
export default ContactMap;
I'm not sure to go from here and it's frustrating. Any help would be appreciated. Thank you.