Put console.log(list) outside handleSearch to get the latest value
const handleSearch = async (e) => {
e.preventDefault();
const proxy = 'https://cors-anywhere.herokuapp.com/';
const url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?';
const location = `location=${latitude},${longitude}`;
const radius = '&radius=2000';
const type = '&keyword=restaurant';
const key = '&key=xxxxxxx';
const SearchUrl = proxy + url + location + radius + type + key;
SetList({list: await myRespone(SearchUrl)})
}
console.log(list);
The update value of useState is asynchronous, you cannot get the latest value synchronously. Only after the hooks update the value, the component re-render can get the updated value
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…