I have a funtion inside a useEffect hook that requests some data to my server:
useEffect(() => {
  const reqFn = async () => {
    // req code...
    setState(req result)
  }
  return reqfn()
},[setState])
Also, I need to run this function when a user clicks on a button to request a different data (reqFn uses a useState value as a prop for the server request).
I've tried taking the reqFn() outside the useEffect, but this makes running reqFn in a loop. How can I achieve this?
 
    