Guide to solving common problems when working with UI8Kit. Find answers to the most frequent questions and issues.
# 1. Package versions
npm list @ui8kit/core react react-dom typescript
# 2. TypeScript compilation
npm run type-check
# 3. Linting
npm run lint
# 4. Build
npm run build// Check import order
import './index.css' // CSS first
import { ThemeProvider } from '@/providers/theme'
import App from './App'
ReactDOM.render(
<ThemeProvider theme={defaultTheme}>
<App />
</ThemeProvider>,
document.getElementById('root')
)Symptoms:
- UI8Kit components don't display
- Styles not applied
- No console errors
Solutions:
// ✅ Correct
import { ThemeProvider } from '@/providers/theme'
import { defaultTheme } from '@/themes'
ReactDOM.render(
<ThemeProvider theme={defaultTheme}>
<App />
</ThemeProvider>,
document.getElementById('root')
)/* src/index.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
/* ... other variables */
}
}// tailwind.config.js
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
// ✅ Required for UI8Kit
"./node_modules/@ui8kit/core/dist/**/*.{js,ts,jsx,tsx}"
],
theme: {
extend: {
colors: {
border: "hsl(var(--border))",
// ... other colors
}
}
}
}Symptoms:
Cannot find module '@ui8kit/core'Property 'variant' does not exist- Red underlines in IDE
Solutions:
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install// tsconfig.json
{
"compilerOptions": {
"moduleResolution": "bundler", // For Vite
"allowImportingTsExtensions": true,
"skipLibCheck": true
}
}// package.json
{
"dependencies": {
"@ui8kit/core": "^0.1.8",
"typescript": "^5.0.0",
"react": "^18.0.0 || ^19.0.0"
}
}Symptoms:
- Incorrect colors or spacing
- Styles not being overridden
- Conflicts with existing styles
Solutions:
/* Correct order */
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
/* Your custom styles after */
.my-custom-class {
/* ... */
}import { cn } from '@ui8kit/core/lib/utils'
<div className={cn(
"bg-red-500 text-white", // Tailwind classes
"hover:bg-red-600" // Modifiers
)}>// tailwind.config.js
export default {
content: [
"./src/**/*.{js,ts,jsx,tsx,html}",
"./node_modules/@ui8kit/core/dist/**/*.{js,ts,jsx,tsx}"
]
}Symptoms:
- Theme doesn't switch
- Colors don't change
- localStorage doesn't save
Solutions:
const { toggleDarkMode, isDarkMode } = useTheme()
// Correct usage
<button onClick={toggleDarkMode}>
{isDarkMode ? '☀️ Light' : '🌙 Dark'}
</button>@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
}
}useEffect(() => {
const root = document.documentElement
root.classList.toggle('dark', isDarkMode)
root.style.colorScheme = isDarkMode ? 'dark' : 'light'
localStorage.setItem('ui:dark', isDarkMode ? '1' : '0')
}, [isDarkMode])Symptoms:
- Slow loading
- Lag during interaction
- High CPU usage
Solutions:
// Dynamic imports
const Modal = lazy(() => import('./Modal'))
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<Modal />
</Suspense>
)
}const MemoizedComponent = memo(function Component({ data }) {
return <div>{data}</div>
})
// Stable callbacks
const handleClick = useCallback(() => {
setCount(c => c + 1)
}, [])# Install analyzer
npm install -D vite-bundle-analyzer
# Analyze
npm run build
npx vite-bundle-analyzer distSymptoms:
- onSubmit not called
- Fields don't update
- Validation doesn't trigger
Solutions:
function ContactForm() {
const [formData, setFormData] = useState({
name: '',
email: '',
message: ''
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault() // ✅ Prevent reload
console.log(formData)
}
const handleChange = (field: string) => (e: React.ChangeEvent<HTMLInputElement>) => {
setFormData(prev => ({ ...prev, [field]: e.target.value }))
}
return (
<Block component="form" onSubmit={handleSubmit}>
<Box component="input" value={formData.name} onChange={handleChange('name')} />
<Button type="submit">Send</Button>
</Block>
)
}// ✅ Controlled
const [value, setValue] = useState('')
<Box component="input" value={value} onChange={e => setValue(e.target.value)} />
// ❌ Uncontrolled
<Box component="input" defaultValue="value" />Symptoms:
- Components don't rearrange on mobile
- Grid doesn't adapt
- Breakpoints ignored
Solutions:
// ✅ Responsive spacing
<Block p={{ base: "md", md: "lg", xl: "xl" }}>
Content
</Block>
// ✅ Responsive grid
<Grid cols="1-2-3-4">
{/* 1 column on mobile, 4 on xl */}
</Grid>// tailwind.config.js
export default {
theme: {
screens: {
'sm': '640px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px'
}
}
}Symptoms:
- Screen readers don't work
- Keyboard navigation doesn't work
- Color contrast issues
Solutions:
// Correct semantics
<Block component="nav" aria-label="Main navigation">
<Group component="ul" role="menubar">
<Block component="li" role="none">
<Button component="a" href="/">Home</Button>
</Block>
</Group>
</Block>
// Screen reader content
<Text className="sr-only">Loading...</Text>// Correct focus flow
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
handleAction()
}
}// Check test setup
// src/test-utils.tsx
import { render, RenderOptions } from '@testing-library/react'
import { ThemeProvider } from '@/providers/theme'
import { defaultTheme } from '@/themes'
const AllTheProviders = ({ children }: { children: React.ReactNode }) => {
return (
<ThemeProvider theme={defaultTheme}>
{children}
</ThemeProvider>
)
}
const customRender = (
ui: React.ReactElement,
options?: Omit<RenderOptions, 'wrapper'>,
) => render(ui, { wrapper: AllTheProviders, ...options })
export * from '@testing-library/react'
export { customRender as render }// For localStorage, matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn()
}))
})// For complex cases
// webpack.config.js
module.exports = {
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@ui8kit/core': path.resolve(__dirname, 'node_modules/@ui8kit/core/dist')
}
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader']
}
]
}
}// For working with local packages
// package.json
{
"workspaces": [
"packages/*",
"apps/*"
]
}// Add in development
if (process.env.NODE_ENV === 'development') {
console.log('UI8Kit Debug:', {
theme: useTheme(),
classes: document.documentElement.className,
cssVariables: getComputedStyle(document.documentElement)
})
}- GitHub Issues: For bug reports
- GitHub Discussions: For questions
- Discord: For quick help
## Problem Description
- What was expected
- What happened
- Steps to reproduce
## Environment
- UI8Kit version: x.x.x
- React version: x.x.x
- TypeScript version: x.x.x
- Browser: Chrome/Firefox/Safari
- OS: Windows/macOS/Linux
## Code Example
```tsx
// Minimal example to reproduce
Console errors or warnings
## 🎯 Prevention
### Regular Checks
1. **Update Dependencies**
```bash
npm update @ui8kit/core
- Check TypeScript
npm run type-check- Analyze Bundle
npm run build && npm run analyze- Test Accessibility
npx axe-core your-app-url- Always use ThemeProvider
- Test components in both themes
- Test on mobile devices
- Monitor performance metrics
- Follow library updates
Following this guide, you'll be able to solve most UI8Kit issues. If the problem persists, don't hesitate to reach out to the community! 🚀