diff --git a/src/components/AttachmentCarousel/createInitialState.js b/src/components/AttachmentCarousel/createInitialState.js index d4c64843c8c9..9c9eb7b777f9 100644 --- a/src/components/AttachmentCarousel/createInitialState.js +++ b/src/components/AttachmentCarousel/createInitialState.js @@ -52,6 +52,7 @@ function createInitialState(props) { const page = _.findIndex(attachments, (a) => a.source === props.source); if (page === -1) { Navigation.dismissModal(); + return; } // Update the parent modal's state with the source and name from the mapped attachments diff --git a/src/components/AttachmentCarousel/index.js b/src/components/AttachmentCarousel/index.js index 6e99abaea61a..3f2524a2992e 100644 --- a/src/components/AttachmentCarousel/index.js +++ b/src/components/AttachmentCarousel/index.js @@ -50,8 +50,10 @@ function AttachmentCarousel(props) { useEffect(() => { const initialState = createInitialState(props); - setPage(initialState.page); - setAttachments(initialState.attachments); + if (initialState) { + setPage(initialState.page); + setAttachments(initialState.attachments); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.reportActions]);