Skip to content

Refactor data hooks to follow React hook rules#41

Open
David-patrick-chuks wants to merge 2 commits into
Adamantine-guild:mainfrom
David-patrick-chuks:feature/refactor-query-hooks
Open

Refactor data hooks to follow React hook rules#41
David-patrick-chuks wants to merge 2 commits into
Adamantine-guild:mainfrom
David-patrick-chuks:feature/refactor-query-hooks

Conversation

@David-patrick-chuks

Copy link
Copy Markdown
Contributor

Overview

This PR refactors feature data hooks so useQuery is called directly from conventional custom hooks instead of from functions returned by parent hooks. It splits the old factory-style hooks into smaller query hooks with shared query key helpers and updates the guild detail and access check screens to consume them at render time.

Related Issue

Closes #15

Changes

🪝 Query Hook Refactor

  • [ADD] src/lib/queryKeys.ts

  • Centralized query key helpers for guild, membership, and access-check queries.

  • [ADD] src/features/guilds/useGuild.ts

  • Added a direct useGuild(guildId) hook and exported createGuildQueryOptions for testability.

  • [ADD] src/features/guilds/useGuildConfig.ts

  • Added a direct useGuildConfig(guildId) hook.

  • [ADD] src/features/guilds/useGuildRoles.ts

  • Added a direct useGuildRoles(guildId) hook.

  • [MODIFY] src/features/membership/useMembership.ts

  • Replaced the factory hook with a direct useMembership(walletAddress, guildId) hook.

  • [ADD] src/features/membership/useUserRoles.ts

  • Added a direct useUserRoles(walletAddress, guildId) hook.

  • [ADD] src/features/access/useAccessCheckResult.ts

  • Added a direct useAccessCheckResult(params) hook for access-check queries.

  • [DELETE] src/features/guilds/useGuilds.ts

  • Removed the factory hook that returned getGuild, getGuildConfig, and getRoles.

  • [DELETE] src/features/access/useAccessCheck.ts

  • Removed the factory hook that returned checkAccess.

📱 Screen Updates

  • [MODIFY] app/guilds/[guildId].tsx

  • Updated the guild detail screen to call useGuild, useMembership, and useGuildRoles directly at render time.

  • [MODIFY] app/access-check.tsx

  • Updated the access check screen to call useAccessCheckResult directly at render time.

  • [MODIFY] app/guilds.tsx

  • Removed an unused membership hook import.

🧪 Tests

  • [ADD] tests/hooks/useGuild.hook.test.ts

  • Added tests verifying the refactored hook calls useQuery at the top level.

  • Added tests for enabled guards, successful fetch, and error propagation.

  • [ADD] tests/hooks/queryKeys.test.ts

  • Added tests for shared guild, membership, and access-check query key helpers.

Verification Results

[npx vitest run tests/hooks/useGuild.hook.test.ts tests/hooks/queryKeys.test.ts ✅ passed (9/9)]

Acceptance Criteria Status
Query hooks are named with the use* convention
useQuery is not called inside arbitrary callback functions
Guild detail screen uses direct custom query hooks
Access check screen uses a direct custom query hook
Existing loading, error, and empty states continue to work
Tests cover at least one refactored query hook

Split factory-style feature hooks into direct use* query hooks with shared query key helpers, and update guild detail and access check screens to call them at render time.

Closes Adamantine-guild#15

@Lakes41 Lakes41 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good Job, Do resolve conflicts @David-patrick-chuks

Resolve conflicts by keeping the refactored useAccessCheckResult hook while integrating upstream QR scanner access-check flow and removing the legacy useAccessCheck module.
@Lakes41

Lakes41 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@David-patrick-chuks Do resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor data hooks to follow React hook rules

2 participants