I think it would be a better architecture if, instead of using setTimeout() to call getData after the latitude and longitude are in state, you moved all of the code inside setTimeout inside showPosition (or a helper function that showPosition) calls. Then you are guaranteed to have the lat and long values, instead of hoping that your setTimeout waits long enough.