Call A Function From onClick in React

August - 2021

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

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:

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