I want to call a useFetch function in my project. I have to get 3 parameters for running this API. I created a function for that but there is an error:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app
26 | export default function ProductTypeList() { 27 | async function ConfirmFunction(credit, userID, operation) { > 28 | return useFetch( 29 | "/credit/add?userId=" +
How can I fix it?
export default function ProductTypeList() { async function ConfirmFunction(credit, userID, operation) { return useFetch( "/credit/add?userId=" + userID + "&amount=" + credit + "&type=" + operation ); } ... return <Button color="primary" onClick={() => ConfirmFunction(selectedAmount, select, selectOperation) } > Okay </Button> Note: All parameters are true.
useunless it's going to be at the Top Level. All functions starting withusewill be treated as a hook.