Skip to content

Instantly share code, notes, and snippets.

@marufsiddiqui
Created May 3, 2024 18:36
Show Gist options
  • Save marufsiddiqui/c6f29c38c05ff11bc77d4aa8ecbed987 to your computer and use it in GitHub Desktop.
Save marufsiddiqui/c6f29c38c05ff11bc77d4aa8ecbed987 to your computer and use it in GitHub Desktop.
findModalFooter
function findModalFooter1(children: ReactNode): ReactNode {
return React.Children.toArray(children).find((child: ReactNode) => {
if (!child || !React.isValidElement(child)) {
return null
}
if (child.type === 'ModalFooter') {
return child
} else if (React.Children.count(child) > 0) {
return findModalFooter(child.props.children)
}
return null
})
}
function findModalFooter(children: ReactNode): ReactNode | null {
return React.Children.toArray(children).find((child: ReactNode) => {
if (!child || !React.isValidElement(child)) {
return null // Skip invalid or non-element children
}
// Check if child is a custom component (GuestOrderForm or InstorePurchaseForm)
if (React.Children.count(child) > 0) {
const foundInChild = findModalFooter(child.props.children)
return foundInChild || null // Return modal footer found within child or null
}
// Check if child is the ModalFooter element
return child.type === 'ModalFooter' ? child : null
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment