swizzle command allows you to export components or functions from Refine packages to customize them in your project. This gives you full control over the UI and behavior without losing the ability to update Refine packages.
Usage
How It Works
Theswizzle command:
- Scans your project for installed Refine packages with swizzle configuration
- Presents an interactive list of packages to choose from
- Shows available components/functions from the selected package
- Exports the selected component to your project’s source directory
- Automatically installs any required dependencies
- Preserves code formatting and imports
What Can Be Swizzled
You can swizzle components and functions from various Refine packages:- UI Framework Packages - Ant Design, Material UI, Mantine, Chakra UI components
- Core Packages - Hooks, utilities, and helper functions
- Data Providers - Provider implementations
- Auth Providers - Authentication logic
Examples
Interactive Mode
Run the swizzle command to start the interactive process:Output
Swizzle an Ant Design Component
Swizzle a table component from Ant Design:- Select Ant Design from the package list
- Select the component you want to customize (e.g.,
<List>,<Edit>,<Show>) - The component will be exported to your
src/componentsdirectory
Output
Swizzle with Auto Dependencies
When you swizzle a component that requires additional packages, they’re automatically installed:Output
Exported File Structure
When you swizzle a component, it’s exported to your source directory with the following structure:- Complete component source code
- All necessary imports
- Type definitions
- Default export for easy importing
Using Swizzled Components
After swizzling a component, import and use it in your application:src/pages/products/list.tsx
Customization Examples
Custom List Component
After swizzling the List component, customize the header:src/components/list/index.tsx
Custom Hook Implementation
Swizzle and modify a core hook:src/hooks/useCustomTable.ts
File Transformations
The swizzle command applies several transformations:- Import Reordering - Organizes imports for better readability
- Code Formatting - Applies Prettier formatting automatically
- Block Parsing - Removes internal swizzle markers
- Path Resolution - Updates relative import paths
Component Groups
Components are organized by groups for easier navigation:Ant Design
- Layout - Sider, Header, Footer, Title
- CRUD - List, Create, Edit, Show
- Fields - Text, Number, Date, Boolean, Email, URL
- Buttons - Create, Edit, Delete, Show, Clone, Refresh
Material UI
- Layout - Sider, Header, Footer, Title
- CRUD - List, Create, Edit, Show
- Fields - Text, Number, Date, Boolean, Email, URL
- Buttons - Create, Edit, Delete, Show, Clone, Refresh
Core
- Hooks - Data hooks, auth hooks, router hooks
- Utilities - Helper functions and utilities
Best Practices
1. Swizzle Only What You Need
Don’t swizzle components unnecessarily. Only export components you need to customize:2. Maintain Compatibility
When customizing swizzled components, maintain the same props interface:3. Document Your Changes
Add comments explaining your customizations:4. Version Control
Commit swizzled components to version control:5. Keep Track of Updates
When updating Refine packages, review changes to swizzled components:Package-Specific Examples
Ant Design Package
Swizzle the Edit component:src/components/edit/index.tsx
Material UI Package
Swizzle the DataGrid component:Core Package
Swizzle a custom hook:Troubleshooting
No Packages Found
If you see “No Refine packages found with swizzle configuration”:Component Already Exists
If the target file already exists:Output
Source Path Not Found
If the source component can’t be found:- Ensure the package is properly installed
- Update to the latest version of the package
- Check package integrity:
Import Errors After Swizzling
If you get import errors after swizzling:- Check your TypeScript configuration
- Verify path aliases in
tsconfig.json:
tsconfig.json
- Restart your development server:
Missing Dependencies
If required packages aren’t installed automatically:Advanced Usage
Custom Component Paths
By default, components are exported tosrc/components/. The path is determined by your project structure.
Re-swizzling Components
To update a swizzled component:- Delete or rename the existing file
- Run
refine swizzleagain - Manually merge your customizations
Swizzle Multiple Components
Swizzle components one at a time, committing after each:Migration Considerations
When updating Refine packages:- Check Breaking Changes - Review changelog for swizzled components
- Test Thoroughly - Swizzled components may need updates
- Re-swizzle if Needed - Compare with new versions and update accordingly