Newbie question with React ajax calls, getJSON, componentDidMount()

Newbie question with React ajax calls, getJSON, componentDidMount()
0.0 0

#1

Hi, just wondering if it’s possible to use getJSON in one of the method of the component I created and store the data inside that method as oppose to use getJSON in the componentDidMount(). Did some research but all indicated that I should use getJSON or any ajax calls in the componentDidMount() method. The reason is because I need to be able to click a button and activate the getJSON call to fetch data. Thank you in advance.


#2

Yeah, that would be fine in a helper function if it’s being called by clicking the button. However, why are you using jQuery when you could use something lighter like Axios or fetch?