Skip to content

Conversation

@alicanerdurmaz
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

The useCustom hook returns a result.data property that always contains an empty object during loading states. This causes type safety issues where TypeScript cannot properly catch potential runtime errors when accessing nested properties.

For example:

const { result } = useCustom<MyData>({ url: "api/endpoint", method: "get" });
// TypeScript doesn't catch this error - result.data is empty object during loading
result.data.someProperty.map(() => console.log);

This is an undocumented breaking change that can lead to runtime errors.

What is the new behavior?

The result property is now deprecated with proper warnings and documentation:

  1. JSDoc deprecation: Added @deprecated comment to the type definition directing users to use query.data?.data
  2. Documentation updated: Added migration guide and examples showing the correct usage pattern
  3. Examples updated: Updated existing examples to use the new recommended pattern

Recommended usage:

const {
  query: { data },
} = useCustom<MyData>({ url: "api/endpoint", method: "get" });
const responseData = data?.data; // Properly typed and null-safe

This provides better type safety and aligns with TanStack Query patterns.

fixes #7088

Notes for reviewers

  • The result property is not removed, only deprecated - this maintains backward compatibility
  • Updated two example files to demonstrate the new pattern with cleaner variable naming
  • The changeset explains the migration path for users

Deprecate `result.data` in favor of `query.data?.data` to fix type safety issues where empty objects during loading could cause runtime errors.

- Add @deprecated JSDoc and warnOnce warning
- Update docs and examples with migration guide
- Maintain backward compatibility

Resolves #7088
@alicanerdurmaz alicanerdurmaz requested a review from a team as a code owner November 11, 2025 14:34
@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: e438b49

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/core Patch

Not sure what this means? Click here to learn what changesets are.

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

@netlify
Copy link

netlify bot commented Nov 11, 2025

Deploy Preview for refine-doc-live-previews ready!

Name Link
🔨 Latest commit e438b49
🔍 Latest deploy log https://app.netlify.com/projects/refine-doc-live-previews/deploys/691465ff20dd0500082bb919
😎 Deploy Preview https://deploy-preview-7110--refine-doc-live-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@refine-bot refine-bot temporarily deployed to deploy-preview-website-7110 November 11, 2025 14:54 Inactive
@cypress
Copy link

cypress bot commented Nov 11, 2025

refine    Run #12343

Run Properties:  status check passed Passed #12343  •  git commit 8af1aa2fff ℹ️: Merge e438b492aafd0ca9ecb70643ca6367be5e54067b into 820981779628219e05eef4c2320a...
Project refine
Branch Review fix/deprecate-use-custom-returned-result-value
Run status status check passed Passed #12343
Run duration 19m 07s
Commit git commit 8af1aa2fff ℹ️: Merge e438b492aafd0ca9ecb70643ca6367be5e54067b into 820981779628219e05eef4c2320a...
Committer Alican Erdurmaz
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 22
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 378
View all changes introduced in this branch ↗︎

@refine-bot refine-bot temporarily deployed to deploy-preview-website-7110 November 12, 2025 07:33 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-7110 November 12, 2025 07:53 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-7110 November 12, 2025 08:15 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-7110 November 12, 2025 08:41 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-7110 November 12, 2025 09:03 Inactive
@AlphaNick15

This comment was marked as spam.

@AlphaNick15

This comment was marked as spam.

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.

[BUG] useCustom return type is incorrect and undocumented v5 breaking change

5 participants