-
-
Notifications
You must be signed in to change notification settings - Fork 51.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(Form): FormContext use a memoized value(#21976) #21980
Conversation
memo 本身也消耗性能,这里好像不明显, 多产生个对象。 |
正常情况下 但是当 虽然这种优化并不常见,4.0里的Form性能也很好了,但是这里的 |
components/form/Form.tsx
Outdated
@@ -74,6 +74,18 @@ const InternalForm: React.ForwardRefRenderFunction<unknown, FormProps> = (props, | |||
const [wrapForm] = useForm(form); | |||
wrapForm.__INTERNAL__.name = name; | |||
|
|||
const formContextValue = React.memo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useMemo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry,已修改
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d72bc19:
|
Codecov Report
@@ Coverage Diff @@
## master #21980 +/- ##
==========================================
+ Coverage 97.93% 97.93% +<.01%
==========================================
Files 306 306
Lines 7024 7026 +2
Branches 1889 1934 +45
==========================================
+ Hits 6879 6881 +2
Misses 145 145
Continue to review full report at Codecov.
|
它的场景是子元素又通过 |
🤔 This is a ...
🔗 Related issue link
#21976
💡 Background and solution
In current,
FormContext.Provider
use an inline Object variable as the value, it will always trigger unintentional renders in consumers whenForm
orForm
's parent re-renders.📝 Changelog
FormContext
use amemoized
value to avoid triggerFormItem
's unintentional rendersFormContext
使用memoized
值避免FormItem
产生额外的渲染☑️ Self Check before Merge