|
1 | 1 | import {
|
2 |
| - useCallback, useEffect, useRef, useState, |
| 2 | + useCallback, useEffect, useRef, |
3 | 3 | } from "react";
|
4 | 4 | import createForm, {
|
5 |
| - IForm, IConfig, ICreateFormProps, IState, initializeState, |
| 5 | + IForm, ICreateFormProps, IState, initializeState, |
6 | 6 | } from "../logic/createForm";
|
7 | 7 | import useUpdate from "./useUpdate";
|
8 | 8 | import useSubscribe from "./useSubscribe";
|
9 | 9 |
|
10 | 10 | export const useForm = <TSchema>(props: ICreateFormProps<TSchema>) => {
|
11 |
| - const [config, setConfig] = useState<IConfig<TSchema>>({ |
12 |
| - schemas: props.schemas, |
13 |
| - extraData: props.extraData || {}, |
14 |
| - initialValues: props.initialValues || {}, |
15 |
| - }); |
16 | 11 | const update = useUpdate();
|
17 | 12 | const _form = useRef<IForm<TSchema>>(null as any);
|
18 | 13 | const _formState = useRef<IState["containerFormState"]>(initializeState.containerFormState);
|
@@ -50,14 +45,13 @@ export const useForm = <TSchema>(props: ICreateFormProps<TSchema>) => {
|
50 | 45 | extraData: props.extraData,
|
51 | 46 | initialValues: props.initialValues,
|
52 | 47 | });
|
53 |
| - setConfig(_form.current.config); |
| 48 | + update(); |
54 | 49 |
|
55 | 50 | _form.current.notify("containers");
|
56 | 51 | _form.current.notify("fields");
|
57 | 52 | }, [props.schemas, props.extraData, props.initialValues]);
|
58 | 53 |
|
59 | 54 | return {
|
60 |
| - config, |
61 | 55 | form: _form.current,
|
62 | 56 | state: _formState.current,
|
63 | 57 | handleSubmit: _form.current.handleSubmit,
|
|
0 commit comments