This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useTodos from "./hooks/useTodos"; | |
const TodoList = () => { | |
const { data, error, isLoading } = useTodos(); | |
if (isLoading) return <p>Loading...</p>; | |
if (error) return <p>{error.message}</p>; | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
└── vite-project/ | |
├── public/ | |
│ └── vite.svg | |
├── src/ | |
│ ├── assets/ | |
│ │ └── react.svg | |
│ ├── App.css | |
│ ├── App.tsx | |
│ ├── index.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
import { useEffect, useState } from "react"; | |
interface Todo { | |
id: number; | |
title: string; | |
userId: number; | |
completed: boolean; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "bootstrap/dist/css/bootstrap.css"; | |
import React from "react"; | |
import ReactDOM from "react-dom/client"; | |
// Import React Query | |
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | |
import App from "./App"; | |
import "./index.css"; | |
// Initiate the client | |
const queryClient = new QueryClient(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApolloServer } from "@apollo/server"; | |
import { startStandaloneServer } from "@apollo/server/standalone"; | |
import { typeDefs } from "./schema"; | |
import { addMocksToSchema } from "@graphql-tools/mock"; | |
import { makeExecutableSchema } from "@graphql-tools/schema"; | |
import { mocks } from "./data"; | |
async function startApolloServer() { | |
const server = new ApolloServer({ | |
schema: addMocksToSchema({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from "graphql-tag"; | |
export const typeDefs = gql` | |
type Query { | |
"Get user array" | |
users: [User!]! | |
} | |
"" | |
type User { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import casual from "casual"; | |
export const mocks = { | |
Query: () => ({ | |
users: () => [...new Array(3)], | |
}), | |
User: () => ({ | |
firstName: () => casual.first_name, | |
lastName: () => casual.last_name, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import usePosts from "./hooks/usePost"; | |
const PostList = () => { | |
const pageSize = 10; | |
const [page, setPage] = useState<number>(1); | |
const { data, error, isLoading } = usePosts({ page, pageSize }); | |
if (isLoading) return <p>Loading...</p>; | |
if (error) return <p>{error.message}</p>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useQuery } from "@tanstack/react-query"; | |
import axios from "axios"; | |
interface Post { | |
id: number; | |
title: string; | |
body: string; | |
userId: number; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import usePosts from "./hooks/usePost"; | |
import React from "react"; | |
const PostList = () => { | |
const pageSize = 10; | |
const { data, error, isLoading, fetchNextPage, isFetchingNextPage } = | |
usePosts({ pageSize }); | |
if (isLoading) return <p>Loading...</p>; |