I have a component which has a logic for following and unfollowing people. On button click, a function should be called which incudes the query logic. But when I press the button, it gives me "error: invalid hook call, hooks and only be called inside of the body of the function component"
These are my 2 functions for following and unfollowing logic:
function onFollowingClick() {
const {isLoading: deleteFollowerLoading} = useQuery(["deleteFollower", myFollowerId], () => {
deleteFollower(myFollowerId)
})
console.log("following call")
}
function onFollowClick() {
const {isLoading:createFollowerLoading} = useQuery("createFollower",
createFollower()
)
console.log("follower call")
}
This is the button where I have called the functions, and it is inside a map function, you can see it in onclick:
return (
<div className={root}>
<div className={body}>
{
myFollowers && myFollowings && !followerLoading && (
followersData.map((e) => {
return(<>
<div className="data">
<Grid templateColumns="repeat(2, 1fr)" width="100%" alignContent="center">
<GridItem w="100%" >
<Flex
mt="10px">
<Avatar
size={isTabletOrMobile ? "xs" : "sm"}
src={e.requested_profile.s3PicURL}
/>
<Text
w="100%"
wrap="off"
ml="5px"
isTruncated
fontSize={isTabletOrMobile ? "sm" : "md"}
>
{e.requested_profile.Userlink}
</Text>
</Flex>
</GridItem>
<GridItem>
<Flex justifyContent="flex-end">
<Button
w="100px"
h="30px"
mt="8px"
onClick = { () => {
if(myFollowings.includes(e.requested_profile.Userlink)){
onFollowingClick()
}
else{
onFollowClick()
}
} }
variant={myFollowings.includes(e.requested_profile.Userlink) ? "outline" : "solid"}
width={isTabletOrMobile ? "50px" : "60px"}>
{
myFollowings.includes(e.requested_profile.Userlink) ? "Following" : "Follow"
}
</Button>
</Flex>
</GridItem>
</Grid>
</div>
</>
)
})
)
}
</div>
</div>
)
please tell me how do I solve this error.