# react-query-extend **Repository Path**: pvfhv/react-query-extend ## Basic Information - **Project Name**: react-query-extend - **Description**: react-query扩展包 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-05 - **Last Updated**: 2024-08-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @pvfhv/react-query-extend - react-query扩展插件 ## 安装 ```base pnpm add -S @pvfhv/react-query-extend ``` ## 使用 ```typescript import { ReactQueryContainer, ReactQueryClientProvider, ReactQueryHooks } from '@pvfhv/react-query-extend'; // 入口文件 function App() { return (
项目入口
); } // 使用useQuery等类的组件 function QueryComponent() { const result = useQuery({ queryKey: ['xxxxxx'], queryFn: () => fetchData(), staleTime: 1000 * 60 * 5, }); return (
使用useQuery类的组件
) } // hooks const { useObserverData, useScroll } = ReactQueryHooks; function ObserverComponent() { const queryClient = useQueryClient() const containerRef = React.useRef(null) const timeRef = React.useRef({ timer: null, span: 0, mouseEnter: false, }) const [domainList, setDomainList] = React.useState total: number }, 'personList'>>(() => { // ['personsData']返回的数据结构 // { // personList: Array<{name: string; age: number}> // total: number // } const viewData = queryClient.getQueryData(['personsData']) as any if (viewData) { return viewData } return { personList: [], } }) useObserverData(['personsData'], setDomainList) useScroll(timeRef, containerRef) // 容器基本样式 // .high-clues-container { // width: 468px; // height: 360px; // overflow: hidden auto; // > div > div:last-child { // margin-bottom: 0; // } // } return (
年龄({domainList.personList.reduce((pre, cur) => pre + cur.age, 0)})
{ timeRef.current.mouseEnter = true }} onMouseLeave={() => { timeRef.current.mouseEnter = false }} > {xxList.length === 0 && } {xxList.length > 0 && (
{xxList.map((item, index) => ( )}
) }
) } ``` ## 手工更新npm [淘宝源](https://npmmirror.com/package/@pvfhv/react-query-extend/home)