diff --git a/src/atoms/list-atom/listAtom.ts b/src/atoms/list-atom/listAtom.ts index fea681d..5cc251c 100644 --- a/src/atoms/list-atom/listAtom.ts +++ b/src/atoms/list-atom/listAtom.ts @@ -66,7 +66,7 @@ export type ListAtom = ExtendFieldAtom< * @internal */ _formFields: Atom; - buildItem(): ListItemForm; + buildItem(fields?: Fields): ListItemForm; } >; @@ -102,22 +102,16 @@ export function listAtom< } } - function buildItem(): ListItemForm { + function buildItem(fields?: Fields): ListItemForm { return listItemForm({ - fields: formBuilder(), + fields: fields ?? formBuilder(), getListNameAtom: (get) => get(self).name, formListAtom: _formListAtom, }); } const makeFormList = (): ListItemForm[] => - formBuilder(config.value).map((fields) => - listItemForm({ - fields, - getListNameAtom: (get) => get(self).name, - formListAtom: _formListAtom, - }), - ); + formBuilder(config.value).map(buildItem); const initialFormListAtom = atomWithDefault(makeFormList); const _formListAtom = atomWithDefault((get) => get(initialFormListAtom)); diff --git a/src/hooks/use-list-actions/useListActions.ts b/src/hooks/use-list-actions/useListActions.ts index f325b10..9740e4e 100644 --- a/src/hooks/use-list-actions/useListActions.ts +++ b/src/hooks/use-list-actions/useListActions.ts @@ -3,7 +3,6 @@ import { useAtomValue, useSetAtom } from "jotai"; import { useCallback, useMemo, useTransition } from "react"; import { ListAtom, ListItem } from "../../atoms/list-atom"; -import { listItemForm } from "../../atoms/list-atom/listItemForm"; export const useListActions = ( listAtom: ListAtom, @@ -24,13 +23,7 @@ export const useListActions = ( const add = useCallback((before?: ListItem, fields?: Fields) => { dispatchSplitList({ type: "insert", - value: fields - ? listItemForm({ - fields, - getListNameAtom: (get) => get(listAtom).name, - formListAtom: atoms._formList, - }) - : atoms.buildItem(), + value: atoms.buildItem(fields), before, }); startTransition(() => {