expo-popcore-app/hooks/CLAUDE.md

55 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

使用apps\popcore\lib\auth.ts中的loomart接口
封装 hooks 供页面使用
实例代码:
```tsx
import { loomart } from "@/lib/auth"
import { ApiError } from "@/lib/types"
import { useState } from "react"
export const useActivates = () => {
const [loading, setLoading] = useState<boolean>(false)
const [error, setError] = useState<ApiError | null>(null)
const [data, setData] = useState<{
activities: {
title: string;
titleEn: string;
desc: string;
descEn: string;
coverUrl: string;
link: string;
createdAt: Date;
updatedAt: Date;
id: string;
videoUrl?: string | null | undefined;
isActive?: boolean | null | undefined;
sortOrder?: number | null | undefined;
}[];
total: number;
page: number;
limit: number;
totalPages: number;
}>()
const load = async () => {
try {
setLoading(true)
const { data, error } = await loomart.activities.list({ isActive: true })
if (error) {
setError(error)
return;
}
setData(data)
} catch (e) {
setLoading(false)
}
}
return {
load,
loading,
error,
data
}
}
```