Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 完善 useQuery 类型定义 (#1350)
Browse files Browse the repository at this point in the history
完善 useQuery 类型定义
  • Loading branch information
iugo committed Nov 3, 2020
1 parent acc84a1 commit 1bfcd22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/remax-runtime/src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useContext } from 'react';
import PageContext from '../PageContext';

export default function useQuery<Q extends Record<string, string> = { [name: string]: string }>(): Q {
export default function useQuery<
Q extends Record<string, string | undefined> = { [name: string]: string | undefined }
>(): Q {
const pageInstance: any = useContext(PageContext)?.page;
return pageInstance?.query;
}
4 changes: 3 additions & 1 deletion packages/remax-runtime/src/hooks/useQuery.web.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useLocation } from '@remax/web';
import qs from 'qs';

export default function useQuery<Q extends Record<string, string> = { [name: string]: string }>(): Q {
export default function useQuery<
Q extends Record<string, string | undefined> = { [name: string]: string | undefined }
>(): Q {
return qs.parse(useLocation().search, { ignoreQueryPrefix: true }) as Q;
}

1 comment on commit 1bfcd22

@vercel
Copy link

@vercel vercel bot commented on 1bfcd22 Nov 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.