import React, { FC, RefObject, useRef, useState } from "react"; import "bootstrap/dist/css/bootstrap.min.css"; import "./App.css"; import { Input as AntInput } from "antd"; import "antd/dist/antd.css"; import { Input, TextField } from "@material-ui/core"; import Form from "react-bootstrap/Form"; import Autocomplete, { usePlacesWidget } from "react-google-autocomplete"; function App() { const inputRef = useRef(null); const antInputRef = useRef(null); const [country, setCountry] = useState("us"); const { ref: materialRef } = usePlacesWidget({ apiKey: process.env.REACT_APP_GOOGLE, onPlaceSelected: (place) => console.log(place), inputAutocompleteValue: "country", options: { componentRestrictions: { country }, }, }); const { ref: bootstrapRef } = usePlacesWidget({ apiKey: process.env.REACT_APP_GOOGLE, onPlaceSelected: (place) => console.log(place), }); const { ref: antRef } = usePlacesWidget({ apiKey: process.env.REACT_APP_GOOGLE, onPlaceSelected: (place) => { //@ts-ignore antInputRef.current.setValue(place?.formatted_address); }, }); return (
Standard HTML { console.log(selected); }} options={{ types: ["geocode", "establishment"], componentRestrictions: { country }, }} defaultValue="Moscow" />
Material UI ( console.log(selected)} /> )} />
Material UI
Bootstrap
Ant Design { antInputRef.current = c; if (c) antRef.current = c.input; }} size="large" />
); } export default App;