-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28615 from kacper-mikolajczak/chat-transition-opt…
…imisation-proposal Improve memoization of LHN by handling the isFocused prop better
- Loading branch information
Showing
3 changed files
with
45 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/components/LHNOptionsList/OptionRowLHNDataWithFocus.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import withCurrentReportID, {withCurrentReportIDPropTypes, withCurrentReportIDDefaultProps} from '../withCurrentReportID'; | ||
import OptionRowLHNData from './OptionRowLHNData'; | ||
|
||
const propTypes = { | ||
...withCurrentReportIDPropTypes, | ||
shouldDisableFocusOptions: PropTypes.bool, | ||
}; | ||
|
||
const defaultProps = { | ||
...withCurrentReportIDDefaultProps, | ||
shouldDisableFocusOptions: false, | ||
}; | ||
|
||
/** | ||
* Wrapper component for OptionRowLHNData that calculates isFocused prop based on currentReportID. | ||
* This is extracted from OptionRowLHNData to prevent unnecessary re-renders when currentReportID changes. | ||
* @returns {React.Component} OptionRowLHNData component with isFocused prop | ||
*/ | ||
function OptionRowLHNDataWithFocus({currentReportID, shouldDisableFocusOptions, ...props}) { | ||
// We only want to pass a boolean to the memoized component, | ||
// instead of a changing number (so we prevent unnecessary re-renders). | ||
const isFocused = !shouldDisableFocusOptions && currentReportID === props.reportID; | ||
|
||
return ( | ||
<OptionRowLHNData | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
isFocused={isFocused} | ||
/> | ||
); | ||
} | ||
|
||
OptionRowLHNDataWithFocus.defaultProps = defaultProps; | ||
OptionRowLHNDataWithFocus.propTypes = propTypes; | ||
OptionRowLHNDataWithFocus.displayName = 'OptionRowLHNDataWithFocus'; | ||
|
||
export default withCurrentReportID(OptionRowLHNDataWithFocus); |