-
Notifications
You must be signed in to change notification settings - Fork 46.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactDOM.useEvent: support custom types #18351
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 84afbf1:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving in advance, with my usual nits
packages/react-dom/src/events/__tests__/DOMModernPluginEventSystem-test.internal.js
Outdated
Show resolved
Hide resolved
custom = ReactDOM.unstable_useEvent('custom-event'); | ||
}).toWarnDev( | ||
'Warning: The event "type" provided to useEvent() does not have a known priority type. ' + | ||
'It is recommended to provide a "priority" option to specify a priority.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is old, but it's only obvious to me now that this isn't clear. What are the possible values of priority? Where can I learn more about it? etc. In a future PR this message should be made verbose, especially if we expect people to start using custom events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The possible values are 0, 1, 2 – for Discrete, user blocking and continious. I think we'll need to expose them from an enum on React maybe, but right now I'm unsure how that would work.
packages/react-dom/src/events/__tests__/DOMModernPluginEventSystem-test.internal.js
Outdated
Show resolved
Hide resolved
packages/react-dom/src/events/__tests__/DOMModernPluginEventSystem-test.internal.js
Outdated
Show resolved
Hide resolved
3f19be9
to
bce8460
Compare
Address feedback Address feedback Address feedback
bce8460
to
84afbf1
Compare
* ReactDOM.useEvent: support custom types
This PR adds support for custom user events to the
useEvent
system. I've also added tests demonstrating them working as expected. I also added an unnecessaryphasedRegistrationNames == null
check inaccumulateTwoPhaseListeners
that never occurs at runtime. This essentially allows this: