ai-real-estate-tool/src/components/SearchBar.tsx

44 lines
1,011 B
TypeScript
Raw Normal View History

2025-05-23 10:44:19 -07:00
import React, { useState,useEffect } from 'react';
2025-04-27 16:24:20 -07:00
const SearchBar = () => {
const [term, setTerm] = useState('');
2025-05-23 10:44:19 -07:00
2025-04-27 16:24:20 -07:00
const submitForm = (event: React.FormEvent<HTMLFormElement>) => {
// Preventing the page from reloading
event.preventDefault();
2025-05-23 10:44:19 -07:00
console.log("print");
2025-04-27 16:24:20 -07:00
// Do something
2025-05-23 10:44:19 -07:00
//alert(term);
console.log("print");
fetch(`https://nominatim.openstreetmap.org/search?q=${term}&format=json&polygon=1&addressdetails=1`)
.then(response => response.json())
2025-06-05 10:06:43 -07:00
.then(response => console.log("printed address: " + response))
2025-04-27 16:24:20 -07:00
}
2025-05-23 10:44:19 -07:00
useEffect(() => {
console.log("print");
},[])
2025-04-27 16:24:20 -07:00
return (
<div className="container">
<form onSubmit={submitForm}>
<input
value={term}
onChange={(e) => setTerm(e.target.value)}
type="text"
placeholder="Enter a term"
className="input"
/>
2025-06-05 10:06:43 -07:00
<button type="submit" className="btn">Submit</button>
2025-04-27 16:24:20 -07:00
</form>
</div>
);
};
export default SearchBar;