Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Call A Function From onClick in React

This is an example of how to call a function from onClick in react to update the state of an item:

Code

const [pageFetchInProgress, setPageFetchInProgress] = React.useState(false)

<button onClick={() => setPageFetchInProgress(true)}>Check Status</button>

This is the fix for this which would start an infinite loop which react kills:

Code

<button onClick={setPageFetchInProgress(true)}>Check Status</button>