Skip to content

Conversation

@nwidynski
Copy link
Contributor

This PR adds compatibility for React's new useEffectEvent hook, with fallback to our legacy shim.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

Thanks for the PR

}, []);
}

export function useEffectEvent<T extends Function>(fn?: T): T {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not really sure why fn was optional.... this is an internal hook for us (not documented), so I think we should probably have it be required, then we can get rid of this extra noop function

@snowystinger
Copy link
Member

Doh, I see we were passing it possibly undefined in utils/src/useEvent.ts, but we should apply your noop specifically there i think. Looks like that hook very specifically allowed for it.
Sorry for the extra noise and thank you. Happy to handle any other transformations as a result of my request if you don't have time.

@nwidynski
Copy link
Contributor Author

nwidynski commented Oct 27, 2025

@snowystinger I'm fine with requiring the argument, but wanted to note that we definitely lose some convenience. With the upgrade to rules-of-hooks you recently performed, the recommended pattern to opt out of reactivity is to wrap callbacks passed via props with useEffectEvent. Often times props are optional, which would require us to provide a noop, making this pretty cumbersome.

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

@snowystinger I'm fine with requiring the argument, but wanted to note that we definitely loose some convenience. With the upgrade to rules-of-hooks you recently performed, the recommended pattern to opt out of reactivity is to wrap callbacks passed via props with useEffectEvent. Often times props are optional, which would require us to provide a noop, making this pretty cumbersome.

Yeah, I see that, though it looks like we've only needed it in one place out of all of our usages. So I'm ok with it, we'll see what the rest of the team thinks.

Thanks again!

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.

2 participants