fluentui
fluentui copied to clipboard
Update defaultProps usage in EventListener component to comply with future changes
Environment Information
- Package version(s): "@fluentui/react-component-event-listener": "~0.63.0"
Describe the issue:
I encountered a warning while using Semantic UI React version 2.1.4, specifically in the Sidebar.js file. The warning message states:
EventListener: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.
After investigating, I found that the warning originates from the EventListener.ts file in the fluentui/react-component-event-listener package.
To address this warning, I propose making the following code changes in the EventListener.ts file:
// Current code
import { useEventListener } from './useEventListener';
import { EventListenerOptions, EventTypes } from './types';
export function EventListener<T extends EventTypes>(props: EventListenerOptions<T>) {
useEventListener(props);
return null;
}
EventListener.defaultProps = {
capture: false,
};
// Proposed code
import { useEventListener } from './useEventListener';
import { EventListenerOptions, EventTypes } from './types';
export function EventListener<T extends EventTypes>({ capture = false, ...props }: EventListenerOptions<T>) {
useEventListener({ capture, ...props });
return null;
}
Priorities and help requested (not applicable if asking question):
Are you willing to submit a PR to fix? Yes
Requested priority: Low