TODO: Combine these two posts into one (or eliminate one if they are duplicates)
This is how I'm fetching data from a remote API via a button's onClick event handler in React.
- This example uses `unpkg.com` to call versions of react and babel to make it stand alone, but the script will function in a regular React app. - The thing that took me the longest to figure out was how to do the trigger itself. I setup a state object that gets updated when the button is pushed which causes a re-render of the component. When that happens, the `useEffect` sees the new state and fires off the fetch. When it's done, it updates the data and returns the state of `pageFetchInProgress` to false. - If the component is re-rendered while "pageFetchInProgress" is false, it doesn't pull the page again. - While the value is true it pulls on every re-render. So, if something else causes a re-render while it was fetching, it would fetch again. You could put in another state variable to watch for this and prevent it from happening.