Skip to content

Commit

Permalink
Merge pull request #14 from teleporthq/fix/undefined-value-in-repeater
Browse files Browse the repository at this point in the history
Attempt to fix case where items is undefined in Repeater
  • Loading branch information
vladgrecu authored Aug 26, 2024
2 parents a86f0a1 + 4ee0bc2 commit dde8fb8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dist/react-components.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const DataProvider = (props) => {

const Repeater = (props) => {
const { items, renderItem, renderEmpty } = props;
if (typeof items === "undefined" || items === null) {
return renderEmpty ? renderEmpty() : null;
}
if ("data" in items && "meta" in items) {
const { data, meta } = items;
if (Array.isArray(data) === false) {
Expand Down
3 changes: 3 additions & 0 deletions dist/react-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const DataProvider = (props) => {

const Repeater = (props) => {
const { items, renderItem, renderEmpty } = props;
if (typeof items === "undefined" || items === null) {
return renderEmpty ? renderEmpty() : null;
}
if ("data" in items && "meta" in items) {
const { data, meta } = items;
if (Array.isArray(data) === false) {
Expand Down
7 changes: 6 additions & 1 deletion src/repeater/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ const Repeater = <T extends unknown, K extends Record<string, unknown>>(
props: RepeaterMetaProps<T, K> | RepeaterBasic<T>
) => {
const { items, renderItem, renderEmpty } = props;

if (typeof items === "undefined" || items === null) {
return renderEmpty ? renderEmpty() : null;
}

if ("data" in items && "meta" in items) {
const { data, meta } = items;

if (Array.isArray(data) === false) {
return null
return null;
}

if (data.length === 0) {
Expand Down

0 comments on commit dde8fb8

Please sign in to comment.