Skip to content

Commit

Permalink
fix forwardRef view list
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Mar 26, 2024
1 parent 2777a09 commit a4f6a06
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/dataviews/src/view-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import classNames from 'classnames';
/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';
import { useAsyncList, useInstanceId } from '@wordpress/compose';
import {
__experimentalHStack as HStack,
Expand Down Expand Up @@ -135,18 +136,19 @@ function ListItem( {
);
}

export default function ViewList( {
view,
fields,
data,
isLoading,
getItemId,
onSelectionChange,
onDetailsChange,
selection,
deferredRendering,
id: preferredId,
} ) {
const ViewList = forwardRef( ( props, ref ) => {
const {
view,
fields,
data,
isLoading,
getItemId,
onSelectionChange,
onDetailsChange,
selection,
deferredRendering,
id: preferredId,
} = props;
const baseId = useInstanceId( ViewList, 'view-list', preferredId );
const shownData = useAsyncList( data, { step: 3 } );
const usedData = deferredRendering ? shownData : data;
Expand Down Expand Up @@ -205,6 +207,7 @@ export default function ViewList( {
className="dataviews-view-list"
role="grid"
store={ store }
ref={ ref }
>
{ usedData.map( ( item ) => {
const id = getItemDomId( item );
Expand All @@ -224,4 +227,5 @@ export default function ViewList( {
} ) }
</Composite>
);
}
} );
export default ViewList;

0 comments on commit a4f6a06

Please sign in to comment.