💡 Proposal - ModalLauncher converted to a hook
See original GitHub issueForma 36 contribution proposal
The problem
The modal pattern is frequently used, but the API of the ModalLauncher util is a bit complex to use. This is a very basic example, but if you look for ModalLauncher
in Contentful’s webapp you can find very complex ones
import {
Modal,
ModalLauncher,
} from '@contentful/forma-36-react-components';
const openMyModal = () => {
return ModalLauncher.open(({ isShown, onClose }) => (
<Modal
isShown={isShown}
onClose={() => onClose()}>
{/* ... */}
</Modal>
));
};
function App() {
return <button onClick={openMyModal}>click me to open the modal</button>
}
The proposed solution
I think we could use some inspiration from the hooks Chakra UI give to their users, specifically the useDisclosure hook which is used for components that “open” and “close” and create a hook that handles the open/close state of the modal and also the callbacks like onClose
and then we would only need to do something like this:
import {
Modal,
useDisclosure,
} from '@contentful/forma-36-react-components';
function App() {
const { isShown, onOpen, onClose } = useDisclosure()
return (
<>
{/* onOpen already sets isShown to true */}
<button onClick={onOpen}>Open Drawer</button>
<Modal
isShown={isShown}
onClose={onClose}> {/* onClose already sets isShown to false */}
{/* ... */}
</Modal>
</>
)
}
Breaking changes
- deprecation of ModalLauncher
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
ModalLauncher - Forma 36
ModalLauncher is a utility that allows calling Modal and ModalConfirm in an imperative code, ... import { ModalLauncher } from '@contentful/f36-components';.
Read more >Where to use a hook? - Write Better Proposals
Obvious places for a hook include any high-level summary of the entire proposal. Depending on the funder, this may be called an executive ......
Read more >HOOK the CLIENT with these Upwork Proposal Tips! - YouTube
HOW do you get hired on Upwork? With an AWESOME proposal that the client can't resist! I've got 5 tips for you today...
Read more >Proposal: useNavigationEffect() hook · Issue #9 - GitHub
To be honest the main problem is naming the two hooks to clarify if the effect is called inside the transitions or outside....
Read more >Carey Hook - Applications Proposal Engineer - LinkedIn
View Carey Hook's profile on LinkedIn, the world's largest professional community. Carey has 15 jobs listed on their profile. See the complete profile...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@suevalov I would then just reject this Proposal, IMO having two ways of doing the same thing is just increasing the confusion and maintainability of the Library
Yeah, IMO the cost of upgrading to the new API is extremely high (especially in the field-editors), so I would be really afraid of removing ModalLauncher.
Let’s close the proposal in this case.