Skip to content

Commit

Permalink
fix: replace useForm with useFormState (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
bocembocem authored Nov 14, 2023
1 parent faf3e8c commit 1e19619
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib/core/components/Form/hooks/useStore.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from 'react';

import _ from 'lodash';
import {useForm} from 'react-final-form';
import {useFormState} from 'react-final-form';

import {DynamicFieldStore, FieldObjectValue, FieldValue, ValidateError} from '../types';
import {transformArrIn} from '../utils';

export const useStore = (name: string) => {
const form = useForm();
const formState = useFormState();
const firstRenderRef = React.useRef(true);
const [store, setStore] = React.useState<DynamicFieldStore>(() => {
const values: FieldObjectValue = transformArrIn({
[name]: _.get(form.getState().values, name),
[name]: _.get(formState.values, name),
});

const initialValue = transformArrIn({
[name]: _.get(form.getState().initialValues, name),
[name]: _.get(formState.initialValues, name),
});

return {
Expand All @@ -26,7 +26,7 @@ export const useStore = (name: string) => {
};
});

const submitFailed = form.getState().submitFailed;
const submitFailed = formState.submitFailed;

const tools = React.useMemo(
() => ({
Expand Down Expand Up @@ -54,11 +54,11 @@ export const useStore = (name: string) => {
React.useEffect(() => {
if (!firstRenderRef.current) {
const values: FieldObjectValue = transformArrIn({
[name]: _.get(form.getState().values, name),
[name]: _.get(formState.values, name),
});

const initialValue = transformArrIn({
[name]: _.get(form.getState().initialValues, name),
[name]: _.get(formState.initialValues, name),
});

setStore({
Expand Down

0 comments on commit 1e19619

Please sign in to comment.