0

Hei, I have an question that how can we callback function when the window is loaded/ document is ready in ReactJS app. In my case, I want to have geolocation and store the location when the React App finish loading so user will have the answer though API right after click button for example. If else, user need to wait to get geolocation after clicking button and it take few moments. Thanks a lot.

trungh13
  • 167
  • 1
  • 3
  • 10
  • 1
    Try adding the callback to the `componentDidMount` of your uppermost component. –  Apr 15 '18 at 20:01
  • 1
    What @LyoshaKorogoda said, just use the lifecycle method of some root component that handles the whole app. When it's mounted, the React is up and you can fire your events. Best post about lifecycle methods is probably this so read up -> http://busypeoples.github.io/post/react-component-lifecycle/ – Sebastijan Dumančić Apr 15 '18 at 20:13
  • I saw something like that also but as Reactjs 16+, things change a lot like they changed for example: getInitialState change into constructors things. Sorry if I understand wrong :D I'm quite new here. – trungh13 Apr 16 '18 at 07:33

0 Answers0