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
interface Todo { | |
userId: number; | |
id: number; | |
title: string; | |
completed: boolean; | |
} | |
async function getData() { | |
const res = await fetch("https://jsonplaceholder.typicode.com/todos"); | |
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
function fetchData(): Promise<string> { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
const data = "Here are some mock data 🤡"; | |
if (data) { | |
resolve(data); | |
} else { | |
reject("Data not found"); | |
} | |
}, 2000); |
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
function fetchUser(userId: number): Promise<string> { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (userId === 1) { | |
resolve("Sung-Jie Hung"); | |
} else { | |
reject("User not found"); | |
} | |
}, 2000); | |
}); |
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
function fetchUser(userId: number): Promise<string> { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (userId === 1) { | |
resolve("Sung-Jie Hung"); | |
} else { | |
reject("User not found"); | |
} | |
}, 2000); | |
}); |
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 { initializeApp } from "firebase/app"; | |
import { getFirestore } from "firebase/firestore"; | |
const firebaseConfig = { | |
apiKey: YOUR_API_KEY, | |
authDomain: YOUR_AUTH_DOMAIN, | |
projectId: YOUR_PROJECT_ID, | |
storageBucket: YOUR_STORAGE_BUCKET, | |
messagingSenderId: YOUR_SENDER_ID, | |
appId: YOUR_APP_ID, |
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
const firebaseConfig = { | |
apiKey: YOUR_API_KEY, | |
authDomain: YOUR_AUTH_DOMAIN, | |
projectId: YOUR_PROJECT_ID, | |
storageBucket: YOUR_STORAGE_BUCKET, | |
messagingSenderId: YOUR_SENDER_ID, | |
appId: YOUR_APP_ID, | |
measurementId: YOUR_MEASUREMENT_ID, | |
}; |
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 { db } from "./firebaseConfig"; | |
import { collection, doc, getDocs, updateDoc } from "firebase/firestore"; | |
async function addData(name: string, age: number, college: string) { | |
const objectsRef = collection(db, "test"); | |
try { | |
const querySnapshot = await getDocs(objectsRef); | |
querySnapshot.forEach(async (docSnapshot) => { | |
const documentId = docSnapshot.id; |
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 { db } from "./firbaseConfig"; | |
import { | |
collection, | |
getDocs, | |
query, | |
where, | |
} from "firebase/firestore"; | |
const queryFirestore = async (name: string) => { | |
const objectsRef = collection(db, "test"); |
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 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 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 ( |
OlderNewer