Skip to content

Commit

Permalink
fix: Do not crash if the component does not find the child
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkur39 committed May 25, 2022
1 parent 2c51a25 commit 57f296b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions react/Viewer/Footer/FooterContent.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, Children, cloneElement } from 'react'
import React, { useMemo, Children, cloneElement, isValidElement } from 'react'
import PropTypes from 'prop-types'
import { makeStyles } from '@material-ui/core/styles'

Expand Down Expand Up @@ -27,16 +27,19 @@ const FooterContent = ({ file, toolbarRef, children }) => {

const { contactName, isLoadingContacts } = useReferencedContactName(file)

const FooterActionButtons = Children.toArray(children).find(child => {
return (
child.type.name === 'FooterActionButtons' ||
child.type.displayName === 'FooterActionButtons'
)
})
const FooterActionButtons =
Children.toArray(children).find(child => {
return (
child.type.name === 'FooterActionButtons' ||
child.type.displayName === 'FooterActionButtons'
)
}) || null

const FooterActionButtonsWithFile = cloneElement(FooterActionButtons, {
file
})
const FooterActionButtonsWithFile = isValidElement(FooterActionButtons)
? cloneElement(FooterActionButtons, {
file
})
: null

// We have to wait for the Contact request to finish before rendering `BottomSheet`, because it doesn't handle async well.
if (isValidForPanel({ file }) && !isLoadingContacts) {
Expand Down

0 comments on commit 57f296b

Please sign in to comment.