Skip to content

Refactor data hooks to follow React hook rules #15

Description

@Lakes41

Summary

Refactor feature hooks so useQuery is called directly from custom hooks instead of from functions returned by hooks. This reduces the risk of rule-of-hooks violations and makes query behaviour easier to test.

Current Behaviour

Hooks such as useGuilds, useMembership, and useAccessCheck return functions like getGuild, getMembership, and checkAccess. Those functions call useQuery internally when invoked by screen components.

Expected Behaviour

Each query should be exposed as a conventional custom hook such as useGuild, useGuildRoles, useMembership, and useAccessCheckResult, with stable arguments and predictable enabled conditions.

Suggested Implementation

Split the current feature hooks into smaller query hooks. Move query key creation into shared helpers. Update screens to call the new hooks directly at component render time.

Files or Areas Likely Affected

  • src/features/guilds/useGuilds.ts
  • src/features/membership/useMembership.ts
  • src/features/access/useAccessCheck.ts
  • app/guilds/[guildId].tsx
  • app/access-check.tsx

Acceptance Criteria

  • 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 or mutation hook
  • Existing loading, error, and empty states continue to work
  • Tests cover at least one refactored query hook

Additional Notes

Assumption: current behaviour may work at runtime, but the current pattern makes hook ordering and linting harder to reason about.

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official Campaign

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions