Home > database >  Use Memo combine into single condition
Use Memo combine into single condition

Time:11-03

I have added the conditon to check the header and footer is value or not

        const hasHeader = !!(children as React.ReactNode[]).find((e) =>
          isComponentType(el, Header)
        );
        return {
          header,
        };
      }, [children]);```

CodePudding user response:

const hasChildComponent = (Component) => {
  return !!(children as React.ReactNode[]).find((el) => isComponentType(el, Component));
}

return {
  hasHeader: hasChildComponent(Modal.Header),
  hasFooter: hasChildComponent(Modal.Footer),
}
  • Related