Skip to content

Commit 46ba3c4

Browse files
committed
Gracefully handle non-array inputs in 'data' prop
1 parent 219c3d2 commit 46ba3c4

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

packages/core/src/components/DeckSwiper/DeckSwiper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const DeckSwiper = <T extends object>({
7070
[childrenArray]
7171
);
7272

73-
const cardsData = data || cardsFillerData;
73+
const cardsData = Array.isArray(data) ? data : cardsFillerData;
7474

7575
const renderCard = (card: any, index: number): JSX.Element => {
7676
if (renderItem) {

packages/core/src/components/SectionList/SectionList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ const SectionList = <T extends { [key: string]: any }>({
4545
renderItem: renderItemProp,
4646
...rest
4747
}: FlatListSectionListProps<T> | FlashListSectionListProps<T>) => {
48-
const data = React.useMemo(() => (dataProp || []) as T[], [dataProp]);
48+
const data = React.useMemo(
49+
() => (Array.isArray(dataProp) ? dataProp : []) as T[],
50+
[dataProp]
51+
);
4952

5053
const dataWithSections = React.useMemo(() => {
5154
const result: SectionListItem<T>[] = [];

packages/core/src/components/Swiper/Swiper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const Swiper = ({
7474

7575
const children: React.ReactNode = React.useMemo(
7676
() =>
77-
data && renderItem
77+
Array.isArray(data) && renderItem
7878
? data.map((item, index) => {
7979
const component = renderItem({ item, index });
8080

packages/core/src/components/Table/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Table = <T extends object>({
5959
return object.isTableHeader;
6060
}, []);
6161

62-
const isRenderItem = data && renderItem;
62+
const isRenderItem = Array.isArray(data) && renderItem;
6363

6464
//Uses 'renderItem' and 'data' to create an array of children
6565
const dataAsChildren = React.useMemo(() => {

packages/maps/src/components/MapView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class MapView<T> extends React.Component<
7878
private getChildrenForType(type: React.ElementType): React.ReactElement[] {
7979
const { markersData, renderItem, keyExtractor, children } = this.props;
8080

81-
if (markersData && renderItem) {
81+
if (Array.isArray(markersData) && renderItem) {
8282
const markers: React.ReactElement[] = [];
8383

8484
markersData.forEach((item, index) => {

0 commit comments

Comments
 (0)