跳到主要内容

1 篇博文 含有标签「react-query」

查看所有标签

· 阅读需 5 分钟
chalk

react-query 基本使用介绍

useQuery

使用查询

  • queryKey 查询键 查询键必须是可序列化的 只要键改变,React-Query 就会自动触发重新获取。

Use Query Key Factories

const todoKeys = {
all: ['todos'] as const,
lists: () => [...todoKeys.all, 'list'] as const,
list: (filters: string) => [...todoKeys.lists(), { filters }] as const,
details: () => [...todoKeys.all, 'detail'] as const,
detail: (id: number) => [...todoKeys.details(), id] as const,
}