ReactJS newbie question. Can someone please enlighten me as to why inputValue.length in the code snippet below is 0 even after I use setInputValue() to set inputValue equal to a string. Note that the input field for which inputValue corresponds does indeed populate with the location string upon using setInputValue(). Any help is greatly appreciated!
const [inputValue, setInputValue] = React.useState('');
const getLocation = () => {
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function (position) {
(async () => {
const location = await Geocoder(position.coords.latitude,position.coords.longitude);
setInputValue(`${location}`);
console.log(inputValue.length);
})()
});
};
};
React.useEffect(() => {
getLocation();
}, []);