import type { FieldDictionary } from '../../types'; import type { FieldListConfig } from './baselist'; /** * A custom hook for utilizing useBaseList. useList uses useBaseList. This hook is responsible for returning just the field objects useBaseList provides. * In it's simplest form `useList` can be called with a single parameter with the list to derive default values and structure from. * * ```typescript * const list = useList([{title: '', description: ''}, {title: '', description: ''}]); * ``` * * You can also pass a more complex configuration object specifying a validation dictionary. * * ```tsx *const list = useList({ * list: [{title: '', description: ''}, {title: '', description: ''}], * validates: { * title:(title) => { * if (title.length > 3) { * return 'Title must be longer than three characters'; * } * }, * description: (description) => { * if (description === '') { * return 'Description is required!'; * } * } * } *}); * ``` * * Generally, you will want to use the list returned from useList by looping over it in your JSX. * ```tsx *function MyComponent() { * const variants = useList([{title: '', description: ''}, {title: '', description: ''}]); * * return ( *
{field.title.error}
} * * {field.description.error &&{field.description.error}
} *