modal▌
lobehub/lobe-chat · updated Apr 8, 2026
Use createModal from @lobehub/ui for imperative modal dialogs.
Modal Imperative API Guide
Use createModal from @lobehub/ui for imperative modal dialogs.
Why Imperative?
| Mode | Characteristics | Recommended |
|---|---|---|
| Declarative | Need open state, render <Modal /> |
❌ |
| Imperative | Call function directly, no state | ✅ |
File Structure
features/
└── MyFeatureModal/
├── index.tsx # Export createXxxModal
└── MyFeatureContent.tsx # Modal content
Implementation
1. Content Component (MyFeatureContent.tsx)
'use client';
import { useModalContext } from '@lobehub/ui';
import { useTranslation } from 'react-i18next';
export const MyFeatureContent = () => {
const { t } = useTranslation('namespace');
const { close } = useModalContext(); // Optional: get close method
return <div>{/* Modal content */}</div>;
};
2. Export createModal (index.tsx)
'use client';
import { createModal } from '@lobehub/ui';
import { t } from 'i18next'; // Note: use i18next, not react-i18next
import { MyFeatureContent } from './MyFeatureContent';
export const createMyFeatureModal = () =>
createModal({
allowFullscreen: true,
children: <MyFeatureContent />,
destroyOnHidden: false,
footer: null,
styles: { body: { overflow: 'hidden', padding: 0 } },
title: t('myFeature.title', { ns: 'setting' }),
width: 'min(80%, 800px)',
});
3. Usage
import { createMyFeatureModal } from '@/features/MyFeatureModal';
const handleOpen = useCallback(() => {
createMyFeatureModal();
}, []);
return <Button onClick={handleOpen}>Open</Button>;
i18n Handling
- Content component:
useTranslationhook (React context) - createModal params:
import { t } from 'i18next'(non-hook, imperative)
useModalContext Hook
const { close, setCanDismissByClickOutside } = useModalContext();
Common Config
| Property | Type | Description |
|---|---|---|
allowFullscreen |
boolean |
Allow fullscreen mode |
destroyOnHidden |
boolean |
Destroy content on close |
footer |
ReactNode | null |
Footer content |
width |
string | number |
Modal width |
Examples
src/features/SkillStore/index.tsxsrc/features/LibraryModal/CreateNew/index.tsx
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.7★★★★★33 reviews- ★★★★★Chinedu Wang· Dec 28, 2024
Keeps context tight: modal is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Shikha Mishra· Dec 24, 2024
modal has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Kofi Malhotra· Dec 20, 2024
modal reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Chinedu Shah· Dec 16, 2024
We added modal from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Yash Thakker· Nov 15, 2024
Solid pick for teams standardizing on skills: modal is focused, and the summary matches what you get after install.
- ★★★★★Ava Liu· Nov 11, 2024
Registry listing for modal matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Li Agarwal· Nov 7, 2024
Useful defaults in modal — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Chinedu Tandon· Nov 3, 2024
modal fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Nikhil Patel· Oct 26, 2024
modal has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★James Brown· Oct 22, 2024
modal is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
showing 1-10 of 33