rameshsyn / react-location-picker

A react component to pick a location using google maps
https://react-location-picker.netlify.app/
MIT License
48 stars 21 forks source link

If you want to update your documentation #19

Closed wicho1001 closed 4 years ago

wicho1001 commented 4 years ago

I just wrote your class component to a functional component. here´s the code

import React, { useState } from "react";
import LocationPicker from 'react-location-picker';

const LocationPickerComponent = () => {

  const defaultPosition = {
    lat: 27.9878,
    lng: 86.9250
  };

  const [location, setLocation] = useState({
    address: "Kala Pattar Ascent Trail, Khumjung 56000, Nepal",
      position: {
         lat: 0,
         lng: 0
    }
  })

  const handleLocationChange = ({ position, address } = location) => {
    setLocation({ position, address });
  }

  React.useEffect(() => {
    handleLocationChange();
  }, [])

  return (
    <>
      <LocationPicker
        containerElement={ <div style={ {height: '100%'} } /> }
        mapElement={ <div style={ {height: '223px'} } /> }
        defaultPosition={defaultPosition}
        onChange={handleLocationChange}
      />
    </>
  )
}

export default LocationPickerComponent;
;
rameshsyn commented 4 years ago

@wicho1001 Sorry for the late attention. If you're still willing to contribute to the docs send a PR updating the docs.