-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add suspense to useProfileFollowers and useProfileFollowing hooks
- Loading branch information
Showing
5 changed files
with
121 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@lens-protocol/react": minor | ||
"@lens-protocol/react-native": minor | ||
"@lens-protocol/react-web": minor | ||
--- | ||
|
||
**feat:** add React Suspense support to `useProfileFollowers` and `useProfileFollowing` hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,75 @@ | ||
import { | ||
Profile, | ||
FollowersRequest, | ||
useFollowers as useFollowersHook, | ||
} from '@lens-protocol/api-bindings'; | ||
import { Profile, FollowersRequest, FollowersDocument } from '@lens-protocol/api-bindings'; | ||
|
||
import { useLensApolloClient } from '../helpers/arguments'; | ||
import { PaginatedArgs, PaginatedReadResult, usePaginatedReadResult } from '../helpers/reads'; | ||
import { PaginatedArgs, PaginatedReadResult } from '../helpers/reads'; | ||
import { | ||
SuspendablePaginatedResult, | ||
SuspenseEnabled, | ||
SuspensePaginatedResult, | ||
useSuspendablePaginatedQuery, | ||
} from '../helpers/suspense'; | ||
import { useFragmentVariables } from '../helpers/variables'; | ||
|
||
/** | ||
* {@link useProfileFollowers} hook arguments | ||
*/ | ||
export type UseProfileFollowersArgs = PaginatedArgs<FollowersRequest>; | ||
|
||
export type { FollowersRequest }; | ||
|
||
/** | ||
* `useProfileFollowers` is a paginated hook that lets you fetch profiles that follow a requested profile. | ||
* {@link useProfileFollowers} hook arguments with Suspense support | ||
* | ||
* @category Profiles | ||
* @group Hooks | ||
* @experimental This API can change without notice | ||
*/ | ||
export type UseSuspenseProfileFollowersArgs = SuspenseEnabled<UseProfileFollowersArgs>; | ||
|
||
/** | ||
* Fetch profiles that follow a requested profile. | ||
* | ||
* @example | ||
* ```tsx | ||
* const { data, loading, error } = useProfileFollowers({ | ||
* of: '0x123', | ||
* }); | ||
* ``` | ||
* | ||
* @category Profiles | ||
* @group Hooks | ||
*/ | ||
export function useProfileFollowers(args: UseProfileFollowersArgs): PaginatedReadResult<Profile[]> { | ||
return usePaginatedReadResult( | ||
useFollowersHook( | ||
useLensApolloClient({ | ||
variables: useFragmentVariables(args), | ||
}), | ||
), | ||
); | ||
export function useProfileFollowers(args: UseProfileFollowersArgs): PaginatedReadResult<Profile[]>; | ||
|
||
/** | ||
* Fetch profiles that follow a requested profile. | ||
* | ||
* This signature supports [React Suspense](https://react.dev/reference/react/Suspense). | ||
* | ||
* ```tsx | ||
* const { data } = useProfileFollowers({ | ||
* of: '0x123', | ||
* suspense: true, | ||
* }); | ||
* | ||
* console.log(data); | ||
* ``` | ||
* | ||
* @experimental This API can change without notice | ||
* @category Profiles | ||
* @group Hooks | ||
*/ | ||
export function useProfileFollowers( | ||
args: UseSuspenseProfileFollowersArgs, | ||
): SuspensePaginatedResult<Profile[]>; | ||
|
||
export function useProfileFollowers({ | ||
suspense = false, | ||
...args | ||
}: UseProfileFollowersArgs & { suspense?: boolean }): SuspendablePaginatedResult<Profile[]> { | ||
return useSuspendablePaginatedQuery({ | ||
suspense, | ||
query: FollowersDocument, | ||
options: useLensApolloClient({ | ||
variables: useFragmentVariables(args), | ||
}), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,75 @@ | ||
import { | ||
Profile, | ||
FollowingRequest, | ||
useFollowing as useFollowingHook, | ||
} from '@lens-protocol/api-bindings'; | ||
import { Profile, FollowingRequest, FollowingDocument } from '@lens-protocol/api-bindings'; | ||
|
||
import { useLensApolloClient } from '../helpers/arguments'; | ||
import { PaginatedArgs, PaginatedReadResult, usePaginatedReadResult } from '../helpers/reads'; | ||
import { PaginatedArgs, PaginatedReadResult } from '../helpers/reads'; | ||
import { | ||
SuspendablePaginatedResult, | ||
SuspenseEnabled, | ||
SuspensePaginatedResult, | ||
useSuspendablePaginatedQuery, | ||
} from '../helpers/suspense'; | ||
import { useFragmentVariables } from '../helpers/variables'; | ||
|
||
/** | ||
* {@link useProfileFollowing} hook arguments | ||
*/ | ||
export type UseProfileFollowingArgs = PaginatedArgs<FollowingRequest>; | ||
|
||
export type { FollowingRequest }; | ||
|
||
/** | ||
* `useProfileFollowing` is a paginated hook that lets you fetch profiles that are followed by a requested profile. | ||
* {@link useProfileFollowing} hook arguments with Suspense support | ||
* | ||
* @category Profiles | ||
* @group Hooks | ||
* @experimental This API can change without notice | ||
*/ | ||
export type UseSuspenseProfileFollowingArgs = SuspenseEnabled<UseProfileFollowingArgs>; | ||
|
||
/** | ||
* Fetch profiles that are followed by a requested profile. | ||
* | ||
* @example | ||
* ```tsx | ||
* const { data, loading, error } = useProfileFollowing({ | ||
* for: '0x123', | ||
* }); | ||
* ``` | ||
* | ||
* @category Profiles | ||
* @group Hooks | ||
*/ | ||
export function useProfileFollowing(args: UseProfileFollowingArgs): PaginatedReadResult<Profile[]> { | ||
return usePaginatedReadResult( | ||
useFollowingHook( | ||
useLensApolloClient({ | ||
variables: useFragmentVariables(args), | ||
}), | ||
), | ||
); | ||
export function useProfileFollowing(args: UseProfileFollowingArgs): PaginatedReadResult<Profile[]>; | ||
|
||
/** | ||
* Fetch profiles that are followed by a requested profile. | ||
* | ||
* This signature supports [React Suspense](https://react.dev/reference/react/Suspense). | ||
* | ||
* ```tsx | ||
* const { data } = useProfileFollowing({ | ||
* for: '0x123', | ||
* suspense: true, | ||
* }); | ||
* | ||
* console.log(data); | ||
* ``` | ||
* | ||
* @experimental This API can change without notice | ||
* @category Profiles | ||
* @group Hooks | ||
*/ | ||
export function useProfileFollowing( | ||
args: UseSuspenseProfileFollowingArgs, | ||
): SuspensePaginatedResult<Profile[]>; | ||
|
||
export function useProfileFollowing({ | ||
suspense = false, | ||
...args | ||
}: UseProfileFollowingArgs & { suspense?: boolean }): SuspendablePaginatedResult<Profile[]> { | ||
return useSuspendablePaginatedQuery({ | ||
suspense, | ||
query: FollowingDocument, | ||
options: useLensApolloClient({ | ||
variables: useFragmentVariables(args), | ||
}), | ||
}); | ||
} |