I'm making a react app with React and GraphQL where I want to default to randomize cocktails, but have an option to look up a specific cocktail through a search after a button click. Hence I need two different queries.
export default function Cocktails() {
const [
dataType,
setDataType
] = useState('randomCocktail');
const [
queryType,
setQueryType
] = useState(RANDOM_COCKTAIL_QUERY);
const { loading, error, data, refetch } = useQuery(queryType);
if (loading) return 'Loading...';
if (error) return `Error! ${error}`;
return (...)
If i try to add a second (lazy) query beneath the default useQuery the program crashes because loading and data has already been assigned. ("Parsing error: Identifier 'loading' has already been declared")
const { loading, error, data, refetch } = useQuery(queryType);
const { loading, data } = useLazyQuery(ONE_COCKTAIL_BY_NAME_QUERY);
I wonder how to best switch between loading in data from different queries. Any help would be greatly appreciated!