| name | mui-component-usage |
| description | null |
Component Usage
Category: mui · Status: 🟢 Active
When to use
Khi cần dựng UI bằng component MUI (Button, TextField, Dialog...) thay vì tự chế lại từ thẻ HTML thô.
Steps
- Ưu tiên component MUI có sẵn; không tự dựng lại bằng
<div>/<button> thuần.
- Dùng đúng prop chuẩn của component (
variant, color, size, disabled) thay vì override bằng CSS.
- Với form, dùng
TextField controlled (value + onChange) hoặc tích hợp form lib.
- Dùng đúng component họ hàng (
Dialog + DialogTitle/DialogContent/DialogActions), không nhồi vào 1 thẻ.
- Tra docs prop trước khi viết logic thủ công cho hành vi MUI đã hỗ trợ.
Template
<Button variant="contained" color="primary" size="medium" onClick={onSave}>
Save
</Button>
<TextField label="Email" value={email} onChange={(e) => setEmail(e.target.value)}
error={!!error} helperText={error} fullWidth />
<Dialog open={open} onClose={onClose}>
<DialogTitle>Confirm</DialogTitle>
<DialogContent>{message}</DialogContent>
<DialogActions>
<Button onClick={onClose}>Cancel</Button>
<Button onClick={onConfirm}>OK</Button>
</DialogActions>
</Dialog>
Example
Good: dùng Button/TextField/Dialog với prop chuẩn, controlled input, đúng cấu trúc con.
Avoid: tự dựng button bằng <div onClick>, override style thay vì dùng prop, nhồi nội dung Dialog không đúng slot.
Checklist