Skip to content

Commit

Permalink
Undefined index while rendering sticky (#674)
Browse files Browse the repository at this point in the history
* undefined check added in render sticky

* lint fix

Co-authored-by: Talha Naqvi <talha.naqvi@shopify.com>
  • Loading branch information
naqvitalha and naqvitalha authored Jan 27, 2022
1 parent 9098c31 commit 269ac85
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/core/sticky/StickyObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,19 @@ export default abstract class StickyObject<P extends StickyObjectProps> extends
}

private _renderSticky(): JSX.Element | JSX.Element[] | null {
const _stickyData: any = this.props.getDataForIndex(this.currentStickyIndex);
const _stickyLayoutType: string | number = this.props.getLayoutTypeForIndex(this.currentStickyIndex);
const _extendedState: object | undefined = this.props.getExtendedState();
const _rowRenderer: ((type: string | number, data: any, index: number, extendedState?: object)
=> JSX.Element | JSX.Element[] | null) = this.props.getRowRenderer();
if (this.props.overrideRowRenderer) {
return this.props.overrideRowRenderer(_stickyLayoutType, _stickyData, this.currentStickyIndex, _extendedState);
} else {
return _rowRenderer(_stickyLayoutType, _stickyData, this.currentStickyIndex, _extendedState);
if (this.currentStickyIndex !== undefined) {
const _stickyData: any = this.props.getDataForIndex(this.currentStickyIndex);
const _stickyLayoutType: string | number = this.props.getLayoutTypeForIndex(this.currentStickyIndex);
const _extendedState: object | undefined = this.props.getExtendedState();
const _rowRenderer: ((type: string | number, data: any, index: number, extendedState?: object)
=> JSX.Element | JSX.Element[] | null) = this.props.getRowRenderer();
if (this.props.overrideRowRenderer) {
return this.props.overrideRowRenderer(_stickyLayoutType, _stickyData, this.currentStickyIndex, _extendedState);
} else {
return _rowRenderer(_stickyLayoutType, _stickyData, this.currentStickyIndex, _extendedState);
}
}
return null;
}

private _getAdjustedOffsetY(offsetY: number): number {
Expand Down

0 comments on commit 269ac85

Please sign in to comment.