I have a search state in react function component.
const [search, setSearch] = React.useState({
orgName: "",
repoName: ""
});
so, when the user submits a form. I need to fetch data from the search object. What I did was:
const handleSearch = (e) => {
e.preventDefault();
const {loading, data, error} = useQuery(SEARCH_REPO, {
variables : {orgName : search.orgName, repoName: search.repoName}
});
};
which violated the react hooks first rule. And I get the error was hooks cannot be used in non react functional component. So, what is the alternative how can I use it. Is it okay to put the useQuery in useEffect hook which will refetch the data when the search object updates?