Skip to content

Instantly share code, notes, and snippets.

View Elgayar's full-sized avatar
🇵🇸
Howa 2allak FE!N?

Mostafa Elgayar Elgayar

🇵🇸
Howa 2allak FE!N?
View GitHub Profile
@Elgayar
Elgayar / fetchingUseQuery.jsx
Created January 10, 2024 09:08
React: Using `useQuery` instead of `useEffect` to perform queries
// https://ah-mahir.medium.com/stop-using-useeffect-2fb4dd3e0332
import React from 'react';
import { useQuery } from 'react-query';
// The function that fetches the data
async function fetchData() {
const res = await fetch('https://api.example.com/data');
if (!res.ok) {
throw new Error('Network response was not ok');
}