Skip to content

Commit eda52f2

Browse files
author
Satish Yadav
committed
Callback success and error function
1 parent 2323359 commit eda52f2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/components/RQSuperHeroes.page.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ import React from 'react';
33
import { useQuery } from '@tanstack/react-query';
44

55
const fetchSuperHeroes = () =>
6-
axios.get('http://localhost:4000/superheroes').then(res => res.data);
6+
axios.get('http://localhost:4000/superheroesd').then(res => res.data);
77

88
function RQSuperHeroesPage() {
9+
const onSuccess = () => {
10+
console.log('Perform side effect after data fetching');
11+
};
12+
const onError = () => {
13+
console.log('Perform side effect after getting error');
14+
};
915
const { isLoading, data, isError, error, isFetching, refetch } = useQuery(
1016
['super-heros'],
1117
fetchSuperHeroes,
12-
{
13-
enabled: false
14-
}
18+
{
19+
onSuccess,
20+
onError,
21+
},
1522
);
1623

1724
return (
1825
<>
1926
<h2>Super Heroes Page</h2>
20-
<button onClick={refetch}>Fetch Heros data</button>
21-
{isFetching && (<h4>Updating...</h4>)}
27+
<button onClick={refetch}>Fetch Heros data</button>
28+
{isFetching && <h4>Updating...</h4>}
2229
{isLoading ? (
2330
<h3>Heros data Loading...</h3>
2431
) : isError ? (

0 commit comments

Comments
 (0)