Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
refactor: change getFromState() to getState()
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed Nov 9, 2020
1 parent 98cd808 commit d23d838
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-guests-judge.md
@@ -0,0 +1,5 @@
---
"react-cool-form": patch
---

refactor: change getFromState() to getState()
4 changes: 2 additions & 2 deletions src/types/index.ts
Expand Up @@ -104,7 +104,7 @@ export interface ValidateRef<V> {
(validate: FieldValidator<V>): (field: FieldElement | null) => void;
}

export interface GetFormState {
export interface GetState {
(path: string | string[] | Record<string, string>, watch?: boolean): any;
}

Expand Down Expand Up @@ -193,7 +193,7 @@ export interface Config<V> {
export interface Return<V> {
formRef: RefObject<HTMLFormElement>;
validate: ValidateRef<V>;
getFormState: GetFormState;
getState: GetState;
setErrors: SetErrors<V>;
setFieldError: SetFieldError;
setValues: SetValues<V>;
Expand Down
4 changes: 2 additions & 2 deletions src/types/react-cool-form.d.ts
Expand Up @@ -61,7 +61,7 @@ declare module "react-cool-form" {
) => void;
}

interface GetFormState {
interface GetState {
(path: string | string[] | Record<string, string>, watch?: boolean): any;
}

Expand Down Expand Up @@ -164,7 +164,7 @@ declare module "react-cool-form" {
export interface Return<V = FormValues> {
formRef: RefObject<HTMLFormElement>;
validate: ValidateRef<V>;
getFormState: GetFormState;
getState: GetState;
setErrors: SetErrors<V>;
setFieldError: SetFieldError;
setValues: SetValues<V>;
Expand Down
16 changes: 8 additions & 8 deletions src/useForm.ts
Expand Up @@ -14,7 +14,7 @@ import {
Fields,
FieldValidator,
FormValues,
GetFormState,
GetState,
Reset,
Return,
SetErrors,
Expand Down Expand Up @@ -170,7 +170,7 @@ export function useForm<V extends FormValues = FormValues>({
[]
);

const getFormState = useCallback<GetFormState>(
const getState = useCallback<GetState>(
(path, watch = true) => {
let state;

Expand Down Expand Up @@ -425,8 +425,8 @@ export function useForm<V extends FormValues = FormValues>({

const getOptions = useCallback(
() => ({
getFormState: ((path, watch = false) =>
getFormState(path, watch)) as GetFormState,
getState: ((path, watch = false) =>
getState(path, watch)) as GetState,
setErrors,
setFieldError,
setValues,
Expand All @@ -436,7 +436,7 @@ export function useForm<V extends FormValues = FormValues>({
reset,
}),
[
getFormState,
getState,
reset,
setErrors,
setFieldError,
Expand Down Expand Up @@ -552,7 +552,7 @@ export function useForm<V extends FormValues = FormValues>({

return {
name,
value: !isUndefined(value) ? value : getFormState(`values.${name}`),
value: !isUndefined(value) ? value : getState(`values.${name}`),
// eslint-disable-next-line react-hooks/rules-of-hooks
onChange: useCallback(
(e) => {
Expand Down Expand Up @@ -583,7 +583,7 @@ export function useForm<V extends FormValues = FormValues>({
},
[
getChangeEventValue,
getFormState,
getState,
handleFieldChange,
setFieldTouchedIfNeeded,
setFieldValue,
Expand Down Expand Up @@ -659,7 +659,7 @@ export function useForm<V extends FormValues = FormValues>({
return {
formRef,
validate: validateRef,
getFormState,
getState,
setErrors,
setFieldError,
setValues,
Expand Down

0 comments on commit d23d838

Please sign in to comment.