React Snipper BookBộ full-file snippets TypeScript / React Native (Expo Web & Snack) cho bài tập BookStore (Bài 10.1 → Bài 10.10 + Bonus 10.11) với React Navigation (Stack + Bottom Tabs) và Redux Toolkit. 1. Khởi tạo & cài đặt thư viện cho full projectChạy trên VS Code (Expo Web)Chạy lần lượt các lệnh sau trong terminal tại thư mục project:
Hoặc dán nhanh vào ô Dependencies trên Snack (
|
| Bài | File cần tạo / sửa | Prefix snippet | Ghi chú |
|---|---|---|---|
| Bước 0 | types.ts (tạo mới) |
on-types-10-0 |
Interface Book, CartItem |
| Bước 0 | theme.ts (tạo mới) |
on-theme-10-0 |
Bảng màu BookStore (navy, indigo, bg, …) |
| Bước 0 | utils.ts (tạo mới) |
on-utils-10-0 |
formatPrice, normalize bỏ dấu tiếng Việt |
| Bước 0 | data/books.ts (tạo mới) |
on-books-10-0 |
Mảng BOOKS 10 sách, getBookById, loadBooks |
| Bài 10.1 | App.tsx |
on-App-10-1 |
Bọc ứng dụng bằng SafeAreaProvider |
| Bài 10.1 | screens/HomeScreen.tsx (tạo mới) |
on-HomeScreen-10-1 |
SafeAreaView, header "📚 BookStore", danh sách cơ bản |
| Bài 10.2 | screens/HomeScreen.tsx |
on-HomeScreen-10-2 |
ActivityIndicator + FlatList (keyExtractor, ✅/❌) |
| Bài 10.3 | components/BookCard.tsx (tạo mới) |
on-BookCard-10-3 |
BookCardProps, TouchableOpacity, Image, React.memo |
| Bài 10.3 | screens/HomeScreen.tsx |
on-HomeScreen-10-3 |
renderItem dùng BookCard + useCallback onSelect |
| Bài 10.4 | components/BookCard.tsx |
on-BookCard-10-4 |
1 component 2 kiểu row / tile, ghép style theo mảng |
| Bài 10.5 | screens/HomeScreen.tsx |
on-HomeScreen-10-5 |
Switch 2 cột (numColumns, key, columnWrapperStyle) + RefreshControl |
| Bài 10.6 | screens/HomeScreen.tsx |
on-HomeScreen-10-6 |
Tìm kiếm không dấu (normalize) + lọc chip thể loại (useMemo) |
| Bài 10.7 | screens/DetailScreen.tsx (tạo mới) |
on-DetailScreen-10-7 |
Màn Chi tiết sách đọc id từ route.params |
| Bài 10.7 | screens/CartScreen.tsx (tạo mới) |
on-CartScreen-10-7 |
Màn Giỏ hàng tạm (chưa nối Redux) |
| Bài 10.7 | screens/FavoritesScreen.tsx (tạo mới) |
on-FavoritesScreen-10-7 |
Màn Yêu thích tạm (chưa nối Redux) |
| Bài 10.7 | navigation.tsx (tạo mới) |
on-navigation-10-7 |
Native Stack (Tabs, Detail) + Bottom Tabs (3 tab) |
| Bài 10.7 | screens/HomeScreen.tsx |
on-HomeScreen-10-7 |
Nhấn thẻ → navigation.navigate("Detail", { id }) |
| Bài 10.7 | App.tsx |
on-App-10-7 |
NavigationContainer + RootNavigator |
| Bài 10.8 | store/cartSlice.ts (tạo mới) |
on-cartSlice-10-8 |
addToCart + selectCartItems, selectCartCount, selectCartTotal |
| Bài 10.8 | store/favoritesSlice.ts (tạo mới) |
on-favoritesSlice-10-8 |
Khung favoritesSlice ban đầu cho store |
| Bài 10.8 | store/index.ts (tạo mới) |
on-store-10-8 |
configureStore, RootState, AppDispatch |
| Bài 10.8 | store/hooks.ts (tạo mới) |
on-hooks-10-8 |
useAppDispatch, useAppSelector có kiểu |
| Bài 10.8 | screens/CartScreen.tsx |
on-CartScreen-10-8 |
Giỏ hàng nối Redux (−, +, xóa, tổng cộng, Xoá giỏ) |
| Bài 10.8 | App.tsx |
on-App-10-8 |
Bọc <Provider store={store}> ngoài cùng |
| Bài 10.9 | store/cartSlice.ts |
on-cartSlice-10-9 |
Hoàn thiện reducer decrease (còn 1 thì xóa khỏi giỏ) |
| Bài 10.9 | screens/DetailScreen.tsx |
on-DetailScreen-10-9 |
Nút "Thêm vào giỏ" gọi dispatch(addToCart(book)) |
| Bài 10.9 | navigation.tsx |
on-navigation-10-9 |
Thêm tabBarBadge trên tab Giỏ hàng (ẩn khi bằng 0) |
| Bài 10.10 | store/favoritesSlice.ts |
on-favoritesSlice-10-10 |
Hoàn thiện toggleFavorite, selectFavoriteIds, selectIsFavorite |
| Bài 10.10 | screens/DetailScreen.tsx |
on-DetailScreen-10-10 |
Nút "♡ Yêu thích" ↔ "♥ Đã yêu thích" màu đỏ |
| Bài 10.10 | screens/FavoritesScreen.tsx |
on-FavoritesScreen-10-10 |
Lọc BOOKS theo ids trong store và hiển thị bằng BookCard |
| Bonus 10.11 | config.ts (tạo mới) |
on-config-10-11 |
Công tắc USE_API và API_URL |
| Bonus 10.11 | store/booksSlice.ts (tạo mới) |
on-booksSlice-10-11 |
createAsyncThunk fetchBooks + extraReducers |
| Bonus 10.11 | store/index.ts |
on-store-10-11 |
Thêm booksReducer vào store |
| Bonus 10.11 | screens/HomeScreen.tsx |
on-HomeScreen-10-11 |
Đọc API khi USE_API = true + màn lỗi (Thử lại / Dùng dữ liệu mảng) |