-
Notifications
You must be signed in to change notification settings - Fork 1.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
Create a consistent API for event handlers in v11 #9641
Comments
joshblack
changed the title
Event handler signatures
Create consistent event handler signatures in v11
Sep 10, 2021
This comment has been minimized.
This comment has been minimized.
joshblack
changed the title
Create consistent event handler signatures in v11
Create a consistent API for event handlers in v11
Sep 10, 2021
|
ProposalControlled components // A change handler is an `onChange` prop for a controlled component
// This handler is generic over the data/state that is made public by the component.
// It should be of type object so that it is easy to modify/extend with additional values
// in the future
type ChangeHandler<T extends object> = (data: T) => void;
function Example() {
const [value, setValue] = React.useState('');
return (
<Sample
value={value}
onChange={(data) => setValue(data.value)}
/>
);
} Controlled components with native In situations where a controlled component may have a native
We have several possible directions forward:
The most compelling options seem to be:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We would like any
on*
or event-handler-related props to have consistent API across the codebase. During an initial review, we noticed that several patterns are floating around the codebase that has been developed throughout the years:(value) => void
(value, event) => void
(event) => void
(event, value) => void
Checklist
The text was updated successfully, but these errors were encountered: