Skip to content

feat(useAsyncEffect): support synchronous cleanup functions - #2958

Merged
crazylxr merged 1 commit into
alibaba:masterfrom
pentaoa:fix/use-async-effect-cleanup
Sep 5, 2026
Merged

crazylxr merged 1 commit into
alibaba:masterfrom
pentaoa:fix/use-async-effect-cleanup

Conversation

@pentaoa

@pentaoa pentaoa commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

Closes #2954

💡 Background and solution

useAsyncEffect currently accepts promises and async generators, but callers cannot return a normal React cleanup function. The hook now detects a synchronous function result and returns it directly from useEffect, preserving React's standard cleanup timing on dependency changes and unmount.

The asynchronous promise/generator cancellation path is unchanged.

📝 Changelog

Language Changelog
🇺🇸 English useAsyncEffect now supports returning a synchronous cleanup function.
🇨🇳 Chinese useAsyncEffect 现在支持返回同步清理函数。

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Validation

  • vitest run packages/hooks/src/useAsyncEffect/__tests__/index.spec.ts (4 tests)
  • tsc --noEmit -p packages/hooks/tsconfig.json
  • Biome formatting check for the four changed files
  • git diff --check

AI assistance

Codex assisted with implementation, type-checking, and tests. I reviewed the complete diff and take responsibility for the change.

@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ahooks@2958
npm i https://pkg.pr.new/@ahooks.js/use-url-state@2958

commit: 0037f43

@crazylxr crazylxr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@crazylxr
crazylxr merged commit 6d7b335 into alibaba:master Sep 5, 2026
9 checks passed
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.

[useAsyncEffect] support cleanpFn too!

2 participants