Lưu array of field objects trong state.
- Render với map, mỗi field có unique id làm key.
- Thêm:
setFields(prev => [...prev, { id: uuid(), value: '' }]). - Xóa:
setFields(prev => prev.filter(f => f.id !== id)). - React Hook Form cung cấp useFieldArray hook xử lý pattern này với performance tốt hơn.
Store an array of field objects in state.
- Render them with map, giving each a unique id as the key.
- Add:
setFields(prev => [...prev, { id: uuid(), value: '' }]). - Remove:
setFields(prev => prev.filter(f => f.id !== id)). - React Hook Form provides the useFieldArray hook that handles this pattern with better performance.