From 3ec54ba11091260b0fd0de3733fd93243abf7b1d Mon Sep 17 00:00:00 2001 From: deadrime Date: Sat, 25 May 2024 23:43:53 +0300 Subject: [PATCH] Add memo --- .gitignore | 30 +++++++----------------------- src/Form.tsx | 4 ++-- src/FormArrayItem.tsx | 8 +++++--- src/FormItem.tsx | 6 ++++-- src/index.ts | 3 ++- src/useForm.tsx | 4 ++-- 6 files changed, 22 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 87b58f0..cbe1187 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,9 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules dist -dist-ssr +node_modules storybook-static -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? +.vscode +.bashrc +.zshenv +.npmrc +public/themes/*.css +bundle.html diff --git a/src/Form.tsx b/src/Form.tsx index 480e44f..74c22ce 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, CSSProperties, useMemo, useEffect } from 'react'; +import React, { useCallback, CSSProperties, useMemo, useEffect, memo } from 'react'; import { FormContext } from './FormContext'; import { FormApi } from './FormApi'; @@ -94,4 +94,4 @@ export const Form = < ); } -export default Form; +export default memo(Form) as typeof Form; diff --git a/src/FormArrayItem.tsx b/src/FormArrayItem.tsx index 83006fb..4d4e715 100644 --- a/src/FormArrayItem.tsx +++ b/src/FormArrayItem.tsx @@ -1,5 +1,5 @@ -import React, { useCallback } from "react" -import { FormItem, FormItemProps } from "./FormItem" +import React, { memo, useCallback } from "react" +import FormItem, { FormItemProps } from "./FormItem" import { FieldUpdate, FieldUpdateCb, ValidationRule } from "./types" import { useField } from "./useForm" import { FormApi } from "./FormApi" @@ -64,7 +64,7 @@ export type FormArrayItemProps, event?: unknown) => unknown } -export const FormArrayItem = ({ children, ...props }: FormArrayItemProps) => { +const FormArrayItem = ({ children, ...props }: FormArrayItemProps) => { const form = useFormInstance(); const formArray = useArrayField(form, props.name); @@ -72,3 +72,5 @@ export const FormArrayItem = children(formArray)} } + +export default memo(FormArrayItem) as typeof FormArrayItem diff --git a/src/FormItem.tsx b/src/FormItem.tsx index 64a99da..c2cbdd0 100644 --- a/src/FormItem.tsx +++ b/src/FormItem.tsx @@ -1,4 +1,4 @@ -import React, { CSSProperties, useCallback, useRef } from 'react'; +import React, { CSSProperties, useCallback, useRef, memo } from 'react'; import { useDebounce } from 'react-use'; import { useFormContext } from './FormContext'; import { ValidationRule, ValidationStatus, ValidationError } from './types'; @@ -28,7 +28,7 @@ export type FormItemProps< validationDebounceDelay?: number } -export const FormItem = (props: FormItemProps) => { +const FormItem = (props: FormItemProps) => { const { children, name, @@ -86,3 +86,5 @@ export const FormItem = >(initialState: State) => { const formApiRef = React.useRef>(new FormApi(initialState));