Skip to content

Commit

Permalink
refactor: onSave hook
Browse files Browse the repository at this point in the history
  • Loading branch information
OysterD3 committed Jan 21, 2024
1 parent e3e6db9 commit bc31237
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/builder-react/src/FormexProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const FormexEditorContext = createContext<{
values: FormexFormValues['items'],
errors: React.BaseSyntheticEvent<object> | undefined,
) => void,
) => void;
) => (e?: React.BaseSyntheticEvent) => void;
}>({
onSave: async (cb) => {
onSave: (cb) => () => {
return cb([], undefined);
},
});
Expand Down Expand Up @@ -201,12 +201,15 @@ const FormexProvider = <TAvailable extends Elements = Elements>({
setActiveId(nanoid());
};

const handleSave = (
cb: (
values: FormexFormValues['items'],
errors: React.BaseSyntheticEvent<object> | undefined,
) => void,
) => form.handleSubmit((values, errors) => cb(values.items, errors))();
const handleSave =
(
cb: (
values: FormexFormValues['items'],
errors: React.BaseSyntheticEvent<object> | undefined,
) => void,
) =>
(e?: React.BaseSyntheticEvent) =>
form.handleSubmit((values, errors) => cb(values.items, errors))(e);

return (
<FormexFieldsContext.Provider value={{ ...fields }}>
Expand Down

0 comments on commit bc31237

Please sign in to comment.