Skip to content
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

feat: support scoped form instance #660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lemonied
Copy link
Contributor

@lemonied lemonied commented Mar 11, 2024

  • add hook Form.useFormInstance
  • Form.useWatch add param "scoped: true"

ant-design/ant-design#47328

Copy link

vercel bot commented Mar 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
field-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2024 4:01pm

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.47%. Comparing base (8268294) to head (8607178).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #660      +/-   ##
==========================================
+ Coverage   99.43%   99.47%   +0.03%     
==========================================
  Files          18       19       +1     
  Lines        1247     1335      +88     
  Branches      288      308      +20     
==========================================
+ Hits         1240     1328      +88     
  Misses          7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

import * as React from 'react';
import type { InternalFormInstance } from './interface';

const FormInstanceContext = React.createContext<InternalFormInstance | undefined>(undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能复用 Context 不,List 其实也是加了一个 Scope 理论上来说不用新加一个

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复用FieldContext的话,会造成一个问题:
在子组件里拿到的FormInstance不等于最顶层的Form.useForm()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

想了一下,确实可以用FieldContext传递FormInstance,已修改 @zombieJ

- add hook Form.useFormInstance
- Form.useWatch add param "scoped: true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants