score:-1

you can make the usehookone return a function that takes two arguments accountid and statementid .

const sethookone = usehookone()
const sethooktwo = usehooktwo()
const sethookthree = usehookthree()

if (producttype === 'sometype') {
  return sethookone(accountid, statementid)
}else if (producttype === 'othertype') {
  return sethooktwo(accountid, statementid)
} else {
  return sethookthree(accountid, statementid)
}

score:1

hooks can't be called into function or conditions

use hook in the root and put condition for each hook.

can you predict the purpose of your code? i think the logical design of the code should just be approached from a different angle

edit with exemple:

// this hook comes from react-router dom to get the url params
const param = const { producttype, accountid, statementid } = useparams();

let apirequest = new productrequestapi();

if(prodtype == "firsttype"){
 apiquest.adress = 'adress.api.com';
apiquest.quest: 'firstrequest';
apiquest.accountid ... etc
}
else if(prodtype == "secondtype"){
...
}

singlehook(apirequest){
//call api with good params and return after

}

score:3

you need to create 3 others components for each scenario. in each component, you can add his own logic.

const param = const { producttype, accountid, statementid } = useparams();

// i need to run a hook that calls a different api according producttype value
if (producttype === 'sometype') {
  return <usehookone accountid={accountid} statementid={statementid} />
} else if (producttype === 'othertype') {
  return <usehooktwo accountid={accountid} statementid={statementid} />
} else {
  return <usehookthree accountid={accountid} statementid={statementid} />
}

and then create 3 new components. example with usehookone

import react from 'react'

const usehookone = (props) => {
  const data = usehookone(props.accountid, props.statementid)
  return (<>yay! logic number 1 based on {data}</>)
}
export default usehookone

Related Query

More Query from same tag