react-component / react-component/field-form
在Form.List的场景下使用 setFields 对应的ListItem不会触发更新
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 286
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 1
Description
JSX
<Form.List name="sights">
{(fields, { add, remove }) => (
<>
{fields.map((field) => (
<Space key={field.key} align="baseline">
<Form.Item
noStyle
shouldUpdate={(prevValues, curValues) =>
prevValues.area !== curValues.area ||
prevValues.sights !== curValues.sights
}
>
{() => (
<Form.Item
{...field}
label="Sight"
name={[field.name, "sight"]}
rules={[
{
required: true,
message: "Missing sight"
}
]}
>
<Select
disabled={!form.getFieldValue("area")}
style={{
width: 130
}}
>
{(sights[form.getFieldValue("area")] || []).map(
(item) => (
<Option key={item} value={item}>
{item}
</Option>
)
)}
</Select>
</Form.Item>
)}
</Form.Item>
<Form.Item
{...field}
label="Price"
name={[field.name, "price"]}
rules={[
{
required: true,
message: "Missing price"
}
]}
>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</Space>
))}
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
block
icon={<PlusOutlined />}
>
Add sights
</Button>
<Button onClick={resetFirstLine}>reset first line</Button>
</Form.Item>
</>
)}
</Form.List>
调用JS
const resetFirstLine = () => {
form.setFieldValue(["sights", 0], {
sight: 1,
price: 123
});
};
当触发 resetFirstLine 的时候页面上的listItem不刷新
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox demo.js and reproduce the update triggered by setFieldValue(["sights", 0], ...). Trace how Form.List and its list item subscriptions respond, then verify that resetting the first item causes the visible fields to rerender with the new values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100