DEV Community

Discussion on: React components composition: how to get it right

Collapse
 
gabrielmlinassi profile image
Gabriel Linassi • Edited

Really good. Thanks for sharing.
@adevnadia since you worked on Jira, I'd like to ask you a question I'm very curious. How do you handle modals? I know it can be very complex handle multiple modal to add/edit/delete. Is it something similar to github.com/eBay/nice-modal-react ?

And I'd love to see some more advanced patterns as well like:
1) compound composition: <Menu.Button></Menu.Button>
2) render propos: <Menu.Item>{({ active }) => <button className={clsx(active ? '' : '')} ></button>}</Menu.Item>
3) custom hooks: const { open, close, isOpen } = useModal
4) return component from custom hooks: const { Modal, open } = useModal

Collapse
 
adevnadia profile image
Nadia Makarevich

Hi @gabrielmlinassi ,

In Jira they use Atlaskit - Atlassian components library. That one: atlassian.design/components/modal-...

As for other composition patterns: you might be interested in this article: developerway.com/posts/react-compo..., I cover render props in detail there.

And this one for custom hooks:
developerway.com/posts/why-custom-..., it covers exactly the usecase of returning a component (Modal) from a hook. In short - not a good idea, prone to bugs and performance issues.