Skip to content

Conversation

alicanerdurmaz
Copy link
Member

@alicanerdurmaz alicanerdurmaz commented Aug 27, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

In Refine v4, hooks return flattened objects where query metadata (loading states, errors, etc.) and result data are mixed at the same level:

Query Hooks (useList, useMany, useOne, useCustom, useInfiniteList):

const { data, isLoading, error, total } = useList();
const { data, isLoading, error } = useMany();

Mutation Hooks (useCreate, useUpdate, useDelete, etc.):

const { mutate, isLoading, error, data } = useCreate();

Table Hooks:

const { tableProps, sorters, filters } = useTable();

What is the new behavior?

In Refine v5, hooks return structured objects that separate query metadata from result data for better type safety and cleaner APIs:

Query Hooks now return query and result properties:

const { 
  query: { isLoading, error },
  result: { data, total }
} = useList();

const {
  query: { isLoading, error },
  result: data
} = useMany();

Mutation Hooks now return mutation, mutate, and mutateAsync properties:

const { 
  mutation: { isLoading, error, data },
  mutate,
  mutateAsync
} = useCreate();

Table Hooks include structured return types:

const { 
  tableProps, 
  sorters, 
  filters,
  reactTable // for react-table integration
} = useTable();

Key improvements:

  • 🔥 Breaking Change: Major API restructuring for all data hooks
  • 🎯 Better Type Safety: Clear separation between query state and result data
  • 🚀 Enhanced Developer Experience: More predictable and consistent API patterns
  • 🔧 Comprehensive Migration: Automated codemods provided for seamless migration
  • 📚 Extensive Updates: 350+ example files updated to demonstrate new patterns

Migration Support:

  • Automated codemods transform existing code patterns
  • Comprehensive test coverage ensures reliability
  • Multiple hook types supported: query hooks, mutation hooks, table hooks
  • All UI library integrations updated (Ant Design, Material-UI, Mantine, Chakra UI)

fixes: Part of Refine 5.0 major version upgrade

Notes for reviewers

🚨 Breaking Changes

This is a major breaking change that fundamentally restructures how Refine hooks return data. Every consumer of these hooks will need to update their destructuring patterns.

🔍 Review Focus Areas

  1. Hook Return Type Structure: Verify query/result separation in query hooks and mutation/mutate/mutateAsync in mutation hooks
  2. Codemod Accuracy: Test automated transformations handle edge cases correctly
  3. Type Safety: Ensure TypeScript definitions provide proper intellisense and error detection
  4. Example Coverage: Confirm all 350+ updated examples demonstrate correct usage patterns
  5. Inferencer Updates: Verify code generation produces correct v5 patterns

Copy link

changeset-bot bot commented Aug 27, 2025

⚠️ No Changeset found

Latest commit: 4517211

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented Aug 27, 2025

@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge August 27, 2025 07:10 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-invoicer-6952/merge August 27, 2025 07:10 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge August 27, 2025 10:24 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-invoicer-6952/merge August 27, 2025 10:24 Inactive
@alicanerdurmaz alicanerdurmaz changed the title Feat/update hook return types feat: update hook return types Aug 27, 2025
@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge August 27, 2025 10:34 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-invoicer-6952/merge August 27, 2025 10:34 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-invoicer-6952/merge August 27, 2025 13:48 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge August 27, 2025 13:48 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge August 29, 2025 11:32 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-client-6952/merge August 29, 2025 11:32 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-antd-6952/merge August 29, 2025 11:33 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-material-ui-6952/merge August 29, 2025 11:33 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge August 29, 2025 13:34 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-invoicer-6952/merge August 29, 2025 13:34 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-client-6952/merge August 29, 2025 13:34 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-antd-6952/merge August 29, 2025 13:34 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-material-ui-6952/merge August 29, 2025 13:35 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-invoicer-6952/merge September 1, 2025 08:30 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-client-6952/merge September 1, 2025 08:30 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-antd-6952/merge September 1, 2025 08:30 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge September 1, 2025 08:31 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-material-ui-6952/merge September 1, 2025 08:31 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-pixels-6952/merge September 2, 2025 08:44 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-client-6952/merge September 2, 2025 08:44 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-antd-6952/merge September 2, 2025 08:44 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-invoicer-6952/merge September 2, 2025 08:44 Inactive
@github-actions github-actions bot temporarily deployed to deploy-preview-finefoods-material-ui-6952/merge September 2, 2025 08:45 Inactive
@erenkurnaz erenkurnaz requested a review from a team as a code owner September 2, 2025 09:25
@erenkurnaz erenkurnaz requested a review from Copilot September 2, 2025 09:47
@erenkurnaz erenkurnaz merged commit 7f1f52a into feat/upgrade-to-refine-5 Sep 2, 2025
91 checks passed
@erenkurnaz erenkurnaz deleted the feat/update-hook-return-types branch September 2, 2025 09:58
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.

4 participants