How to Use Mantine for Building Beautiful React Components: A Practical Guide
Mantine is a modern React component library that offers 100+ customizable components and hooks, built with accessibility and dark mode in mind. It uses CSS-in-JS (Emotion) for styling, making it easy to integrate into any React project. Whether you need forms, modals, notifications, or data tables, Mantine provides a polished, production-ready solution with minimal boilerplate.
To get started, install the core package and its dependencies: npm install @mantine/core @mantine/hooks @mantine/notifications @mantine/form. Then add the MantineProvider wrapping your app (usually in index.js) to enable themes and global styles. You can choose a default theme or customize colors, spacing, and typography via the theme prop.
Essential Components to Use
Buttons and Inputs
Mantine’s Button supports variants (filled, outline, light) and sizes. Use TextInput with built-in validation via @mantine/form. Example:
<Button variant="filled" color="blue">Submit</Button><TextInput label="Name" required />
Modals and Drawers
Modals require a state hook. Use useDisclosure from @mantine/hooks to control open/close. Example:
- Define
const [opened, { open, close }] = useDisclosure(false) - Render
<Modal opened={opened} onClose={close} title="Hello">Content</Modal>
Customizing with Theme
Override the default theme by passing a theme object to MantineProvider. Change primary color, font family, border radius, or add dark mode with colorScheme="dark". Example:
<MantineProvider theme={{ primaryColor: 'teal', defaultRadius: 'lg' }}>
Mantine also includes hooks like useMediaQuery for responsive design and useLocalStorage for persisting state. With its excellent documentation and TypeScript support, Mantine is an excellent choice for building consistent, beautiful React interfaces quickly.