Skip to content

use TearDown bound instead of FnOnce() for effect hooks#62

Merged
jetli merged 2 commits intojetli:mainfrom
Madoshakalaka:fix/teardown-bound
Mar 19, 2026
Merged

use TearDown bound instead of FnOnce() for effect hooks#62
jetli merged 2 commits intojetli:mainfrom
Madoshakalaka:fix/teardown-bound

Conversation

@Madoshakalaka
Copy link
Copy Markdown
Contributor

Fixes #61

Fixes jetli#61. Replaces the old `Destructor: FnOnce() + 'static` bound with
`Destructor: TearDown` on use_effect_once, use_effect_update, and
use_effect_update_with_deps, so users no longer need to return `|| ()`
when there is no cleanup logic.
@jetli
Copy link
Copy Markdown
Owner

jetli commented Mar 18, 2026

hi, is this a break change for end user?

@jetli jetli merged commit e472c9f into jetli:main Mar 19, 2026
1 check passed
@Madoshakalaka
Copy link
Copy Markdown
Contributor Author

No. It's strictly more permissive. TearDown is implemented for:

  • F: FnOnce() + 'static - so all existing code returning closures (e.g. || cleanup() or || ()) still compiles unchanged
  • () - this is the new case that was previously disallowed

No existing call sites break; they just gain the ability to omit the destructor.

Good choice releasing in 0.6.1 I think

@Madoshakalaka Madoshakalaka deleted the fix/teardown-bound branch March 19, 2026 04:38
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.

use_effect_once and use_effect_update still require an explicit destructor

2 participants