From 22ae95ca3a9e6fda413c856213da985bd647cc52 Mon Sep 17 00:00:00 2001 From: Konstantine Kalbazov Date: Tue, 16 Jul 2024 12:58:40 +0200 Subject: [PATCH] Remove defaultProps (use default parameters) This fixes React warnings: "Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead." --- packages/component/src/BasicScrollToBottom.js | 24 +------------------ packages/component/src/EventSpy.js | 6 +---- .../ScrollToBottom/AutoHideFollowButton.js | 7 +----- .../component/src/ScrollToBottom/Composer.js | 20 ++++------------ .../component/src/ScrollToBottom/Panel.js | 5 ---- 5 files changed, 7 insertions(+), 55 deletions(-) diff --git a/packages/component/src/BasicScrollToBottom.js b/packages/component/src/BasicScrollToBottom.js index ac0e29b..9c6cb1d 100644 --- a/packages/component/src/BasicScrollToBottom.js +++ b/packages/component/src/BasicScrollToBottom.js @@ -22,13 +22,6 @@ const BasicScrollToBottomCore = ({ children, className, followButtonClassName, s ); }; -BasicScrollToBottomCore.defaultProps = { - children: undefined, - className: undefined, - followButtonClassName: undefined, - scrollViewClassName: undefined -}; - BasicScrollToBottomCore.propTypes = { children: PropTypes.any, className: PropTypes.string, @@ -43,7 +36,7 @@ const BasicScrollToBottom = ({ debounce, debug, followButtonClassName, - initialScrollBehavior, + initialScrollBehavior = 'smooth', mode, nonce, scroller, @@ -70,21 +63,6 @@ const BasicScrollToBottom = ({ ); -BasicScrollToBottom.defaultProps = { - checkInterval: undefined, - children: undefined, - className: undefined, - debounce: undefined, - debug: undefined, - followButtonClassName: undefined, - initialScrollBehavior: 'smooth', - mode: undefined, - nonce: undefined, - scroller: undefined, - scrollViewClassName: undefined, - styleOptions: undefined -}; - BasicScrollToBottom.propTypes = { checkInterval: PropTypes.number, children: PropTypes.any, diff --git a/packages/component/src/EventSpy.js b/packages/component/src/EventSpy.js index eb6f12e..bbe16b2 100644 --- a/packages/component/src/EventSpy.js +++ b/packages/component/src/EventSpy.js @@ -2,7 +2,7 @@ import { useCallback, useLayoutEffect, useMemo, useRef } from 'react'; import debounceFn from './debounce'; -const EventSpy = ({ debounce, name, onEvent, target }) => { +const EventSpy = ({ debounce = 200, name, onEvent, target }) => { // We need to save the "onEvent" to ref. // This is because "onEvent" may change from time to time, but debounce may still fire to the older callback. const onEventRef = useRef(); @@ -38,8 +38,4 @@ const EventSpy = ({ debounce, name, onEvent, target }) => { return false; }; -EventSpy.defaultProps = { - debounce: 200 -}; - export default EventSpy; diff --git a/packages/component/src/ScrollToBottom/AutoHideFollowButton.js b/packages/component/src/ScrollToBottom/AutoHideFollowButton.js index 5b581d7..2924002 100644 --- a/packages/component/src/ScrollToBottom/AutoHideFollowButton.js +++ b/packages/component/src/ScrollToBottom/AutoHideFollowButton.js @@ -27,7 +27,7 @@ const ROOT_STYLE = { } }; -const AutoHideFollowButton = ({ children, className }) => { +const AutoHideFollowButton = ({ children, className = '' }) => { const [sticky] = useSticky(); const rootCSS = useStyleToClassName()(ROOT_STYLE); const scrollToEnd = useScrollToEnd(); @@ -41,11 +41,6 @@ const AutoHideFollowButton = ({ children, className }) => { ); }; -AutoHideFollowButton.defaultProps = { - children: undefined, - className: '' -}; - AutoHideFollowButton.propTypes = { children: PropTypes.any, className: PropTypes.string diff --git a/packages/component/src/ScrollToBottom/Composer.js b/packages/component/src/ScrollToBottom/Composer.js index 920e788..f0cc54a 100644 --- a/packages/component/src/ScrollToBottom/Composer.js +++ b/packages/component/src/ScrollToBottom/Composer.js @@ -46,14 +46,14 @@ function isEnd(animateTo, mode) { } const Composer = ({ - checkInterval, + checkInterval = 100, children, - debounce, + debounce = 17, debug: debugFromProp, - initialScrollBehavior, + initialScrollBehavior = 'smooth', mode, nonce, - scroller, + scroller = DEFAULT_SCROLLER, styleOptions }) => { const debug = useMemo(() => createDebug(``, { force: debugFromProp }), [debugFromProp]); @@ -609,18 +609,6 @@ const Composer = ({ ); }; -Composer.defaultProps = { - checkInterval: 100, - children: undefined, - debounce: 17, - debug: undefined, - initialScrollBehavior: 'smooth', - mode: undefined, - nonce: undefined, - scroller: DEFAULT_SCROLLER, - styleOptions: undefined -}; - Composer.propTypes = { checkInterval: PropTypes.number, children: PropTypes.any, diff --git a/packages/component/src/ScrollToBottom/Panel.js b/packages/component/src/ScrollToBottom/Panel.js index 9976cc7..b33efc3 100644 --- a/packages/component/src/ScrollToBottom/Panel.js +++ b/packages/component/src/ScrollToBottom/Panel.js @@ -22,11 +22,6 @@ const Panel = ({ children, className }) => { ); }; -Panel.defaultProps = { - children: undefined, - className: undefined -}; - Panel.propTypes = { children: PropTypes.any, className: PropTypes.string