building out frontend UI for stickies
This commit is contained in:
0
frontend/resias/src/components/button.tsx
Normal file
0
frontend/resias/src/components/button.tsx
Normal file
24
frontend/resias/src/components/stickies.tsx
Normal file
24
frontend/resias/src/components/stickies.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
|
||||
const fetchStickies = async () => {
|
||||
const response = await fetch('https://<backend-url>/v1/stickies');
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const Stickies = () => {
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ['stickies'],
|
||||
queryFn: fetchStickies,
|
||||
});
|
||||
|
||||
if (isLoading) return <div>Loading...</div>;
|
||||
if (error) return <div>Error: {error.message}</div>;
|
||||
|
||||
return <div>{data.map((sticky: any) => <div key={sticky.id}>{sticky.text}</div>)}</div>;
|
||||
};
|
||||
|
||||
export default Stickies;
|
||||
@@ -1,6 +1,7 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
@@ -9,7 +10,9 @@ const queryClient = new QueryClient();
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</QueryClientProvider>
|
||||
</StrictMode>,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
|
||||
import Stickies from '../components/stickies';
|
||||
|
||||
const Home = () => {
|
||||
return (
|
||||
<div>
|
||||
<h1>Home</h1>
|
||||
<h1>Resias - </h1>
|
||||
<Stickies />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user