Skip to content

Commit

Permalink
Add react-query provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ddrosario committed Feb 22, 2024
1 parent fe8efa4 commit 71aad06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions client/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import App from './App.jsx';
import './index.css';
import '@mantine/core/styles.css';
Expand All @@ -9,8 +10,10 @@ import { MantineProvider } from '@mantine/core';

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<MantineProvider theme={theme}>
<App />
</MantineProvider>
<QueryClientProvider client={QueryClient}>
<MantineProvider theme={theme}>
<App />
</MantineProvider>
</QueryClientProvider>
</React.StrictMode>,
);
16 changes: 16 additions & 0 deletions client/src/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import React from 'react';
import { useQuery } from '@tanstack/react-query';

function Index() {
const { isFetching, error, data } = useQuery({
queryKey: ['users'],
queryFn: () =>
fetch('/api/v1/users').then((res) => {
return res.json();
}),
});
if (isFetching) {
return <main>Index is loading</main>;
}

if (error) {
return <main>Index is failed</main>;
}

return <main>Index is working</main>;
}

Expand Down

0 comments on commit 71aad06

Please sign in to comment.